Merge branch 'master' of ssh://lx-office/~/lx-office-erp
authorSven Schöling <s.schoeling@linet-services.de>
Fri, 23 Oct 2009 16:35:32 +0000 (18:35 +0200)
committerSven Schöling <s.schoeling@linet-services.de>
Fri, 23 Oct 2009 16:35:32 +0000 (18:35 +0200)
52 files changed:
SL/AR.pm
SL/CA.pm
SL/ReportGenerator.pm
SL/USTVA.pm
am.pl
bin/mozilla/acctranscorrections.pl
bin/mozilla/admin.pl
bin/mozilla/admin_groups.pl
bin/mozilla/am.pl
bin/mozilla/amcvar.pl
bin/mozilla/amtemplates.pl
bin/mozilla/ap.pl
bin/mozilla/ar.pl
bin/mozilla/arap.pl
bin/mozilla/bp.pl
bin/mozilla/ca.pl
bin/mozilla/common.pl
bin/mozilla/ct.pl
bin/mozilla/datev.pl
bin/mozilla/dn.pl
bin/mozilla/do.pl
bin/mozilla/drafts.pl
bin/mozilla/fu.pl
bin/mozilla/generictranslations.pl
bin/mozilla/gl.pl
bin/mozilla/ic.pl
bin/mozilla/installationcheck.pl
bin/mozilla/invoice_io.pl
bin/mozilla/io.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/kopf.pl
bin/mozilla/licenses.pl
bin/mozilla/login.pl
bin/mozilla/menu.pl
bin/mozilla/menuXML.pl
bin/mozilla/menujs.pl
bin/mozilla/menunew.pl
bin/mozilla/menuv3.pl
bin/mozilla/menuv4.pl
bin/mozilla/oe.pl
bin/mozilla/pe.pl
bin/mozilla/projects.pl
bin/mozilla/rc.pl
bin/mozilla/reportgenerator.pl
bin/mozilla/rp.pl
bin/mozilla/todo.pl
bin/mozilla/wh.pl
doc/programmierstilrichtlinien.txt
kopf.pl
login.pl
t/002goodperl.t

index 3364c86..b48741d 100644 (file)
--- a/SL/AR.pm
+++ b/SL/AR.pm
@@ -40,8 +40,6 @@ use SL::MoreCommon;
 
 use strict;
 
-our (%myconfig, $form);
-
 sub post_transaction {
   $main::lxdebug->enter_sub();
 
@@ -526,19 +524,21 @@ sub setup_form {
 
   my ($self, $form) = @_;
 
-  my ($exchangerate, $key, $akey, $i, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate,
+  my ($exchangerate, $akey, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate,
       $totalamount, $taxincluded, $tax);
 
   # forex
   $form->{forex} = $form->{exchangerate};
   $exchangerate  = $form->{exchangerate} ? $form->{exchangerate} : 1;
 
-  foreach $key (keys %{ $form->{AR_links} }) {
+  foreach my $key (keys %{ $form->{AR_links} }) {
     # if there is a value we have an old entry
     $j = 0;
     $k = 0;
 
-    for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
+    next unless $form->{acc_trans}{$key};
+
+    for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
       if ($key eq "AR_paid") {
         $j++;
         $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno};
@@ -609,7 +609,7 @@ sub setup_form {
   if ($form->{taxincluded} && $form->{taxrate} && $totalamount) {
 
     # add tax to amounts and invtotal
-    for $i (1 .. $form->{rowcount}) {
+    for my $i (1 .. $form->{rowcount}) {
       $taxamount            = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount;
       $tax                  = $form->round_amount($taxamount, 2);
       $diff                += ($taxamount - $tax);
index 4f66c9b..460c529 100644 (file)
--- a/SL/CA.pm
+++ b/SL/CA.pm
@@ -304,7 +304,7 @@ sub all_transactions {
       qq| AND ac.chart_id = ? | .
       qq| AND ac.trans_id = a.id | .
       qq| AND a.vendor_id = v.id | .
-      qq| AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)| .
+      qq| AND (NOT ac.ob_transaction OR ac.ob_transaction IS NULL)|;
     push(@values,
          @where_values, @department_values, @project_values, $id,
          @where_values, @department_values, @project_values, $id,
index 6c61acb..402f89d 100644 (file)
@@ -1,7 +1,6 @@
 package SL::ReportGenerator;
 
-#use strict;
-
+use Data::Dumper;
 use Encode;
 use IO::Wrap;
 use List::Util qw(max);
@@ -338,7 +337,7 @@ sub prepare_html_content {
           next;
         }
 
-        my $col = $row->{$col_name};
+        my $col = $row->{$col_name} || { data => [] };
         $col->{CELL_ROWS} = [ ];
         foreach my $i (0 .. scalar(@{ $col->{data} }) - 1) {
           push @{ $col->{CELL_ROWS} }, {
index 84cc17d..88ed9ab 100644 (file)
@@ -497,9 +497,9 @@ sub stichtag {
   #$stichtag =~ /([\d]\d)(\d\d)$/
   #$stichtag = "$1.$2.$yy"
   #$stichtag=$1;
-  our $description; # most probably not existant.
-  our $tage_bis;    # most probably not existant.
-  our $ical;        # most probably not existant.
+  our $description; # most probably not existent.
+  our $tage_bis;    # most probably not existent.
+  our $ical;        # most probably not existent.
 
   $main::lxdebug->leave_sub();
   return ($stichtag, $description, $tage_bis, $ical);
diff --git a/am.pl b/am.pl
index e08d6cb..a70e452 100755 (executable)
--- a/am.pl
+++ b/am.pl
@@ -30,7 +30,7 @@
 #
 #######################################################################
 
-#use strict;
+use strict;
 
 BEGIN {
   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
index 78d21b0..3518562 100644 (file)
@@ -6,19 +6,27 @@ use YAML;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 sub analyze_filter {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{jsscript} = 1;
   $form->{title}    = $locale->text('General ledger corrections');
   $form->header();
   print $form->parse_html_template('acctranscorrections/analyze_filter');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub analyze {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('General ledger corrections');
 
@@ -36,7 +44,7 @@ sub analyze {
   if (!scalar @problems) {
     $form->show_generic_information($locale->text('No problems were recognized.'));
 
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -46,11 +54,14 @@ sub analyze {
                                      'callback' => $callback,
                                    });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub assistant {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
@@ -68,7 +79,7 @@ sub assistant {
     $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
                                                   "$module $form->{trans_reference}"));
 
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -83,22 +94,28 @@ sub assistant {
     $form->show_generic_error($locale->text('Unknown problem type.'));
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub assistant_for_ap_ar_wrong_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
   $form->header();
   print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub fix_ap_ar_wrong_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $analyzer = AccTransCorrections->new();
   $analyzer->fix_ap_ar_wrong_taxkeys();
@@ -107,22 +124,28 @@ sub fix_ap_ar_wrong_taxkeys {
   $form->header();
   print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub assistant_for_invoice_inventory_with_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
   $form->header();
   print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub fix_invoice_inventory_with_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $analyzer  = AccTransCorrections->new();
   $analyzer->fix_invoice_inventory_with_taxkeys();
@@ -131,11 +154,14 @@ sub fix_invoice_inventory_with_taxkeys {
   $form->header();
   print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub assistant_for_wrong_taxes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $problem = shift;
 
@@ -144,11 +170,14 @@ sub assistant_for_wrong_taxes {
   $form->header();
   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub assistant_for_wrong_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $problem = shift;
 
@@ -157,11 +186,14 @@ sub assistant_for_wrong_taxkeys {
   $form->header();
   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub fix_wrong_taxkeys {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
 
@@ -172,11 +204,14 @@ sub fix_wrong_taxkeys {
   $form->header();
   print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Delete transaction');
   $form->header();
@@ -190,18 +225,23 @@ sub delete_transaction {
     print $form->parse_html_template('acctranscorrections/delete_transaction');
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub redirect {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   $form->redirect('Missing callbcak');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub dispatcher {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
     if ($form->{"action_${action}"}) {
       call_sub($action);
index 0282198..a08891a 100755 (executable)
@@ -32,7 +32,7 @@
 #
 #======================================================================
 
-$menufile = "menu.ini";
+my $menufile = "menu.ini";
 
 use DBI;
 use CGI;
@@ -55,13 +55,13 @@ use SL::DBUtils;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/admin_groups.pl";
 
-our $cgi = new CGI('');
-
-$form = new Form;
-
-$locale = new Locale $language, "admin";
+use strict;
 
+our $cgi    = new CGI('');
+our $form   = new Form;
+our $locale = new Locale $main::language, "admin";
 our $auth = SL::Auth->new();
+
 if ($auth->session_tables_present()) {
   $auth->expire_sessions();
   $auth->restore_session();
@@ -78,7 +78,7 @@ $form->{stylesheet} = "lx-office-erp.css";
 $form->{favicon}    = "favicon.ico";
 
 if ($form->{action}) {
-  if ($auth->authenticate_root($form->{rpw}, 0) != Auth::OK) {
+  if ($auth->authenticate_root($form->{rpw}, 0) != $auth->OK()) {
     $form->{error_message} = $locale->text('Incorrect Password!');
     adminlogin();
     exit;
@@ -88,7 +88,7 @@ if ($form->{action}) {
 
   call_sub($locale->findsub($form->{action}));
 
-} elsif ($auth->authenticate_root($form->{rpw}, 0) == Auth::OK) {
+} elsif ($auth->authenticate_root($form->{rpw}, 0) == $auth->OK()) {
 
   $auth->create_or_refresh_session() if ($auth->session_tables_present());
 
@@ -108,6 +108,8 @@ if ($form->{action}) {
 # end
 
 sub adminlogin {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = qq|Lx-Office ERP $form->{version} | . $locale->text('Administration');
 
@@ -121,16 +123,19 @@ sub login {
 }
 
 sub logout {
-  $auth->destroy_session();
+  $main::auth->destroy_session();
   adminlogin();
 }
 
 sub check_auth_db_and_tables {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   my %params;
 
-  map { $params{"db_${_}"} = $auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} };
+  map { $params{"db_${_}"} = $main::auth->{DB_config}->{$_} } keys %{ $auth->{DB_config} };
 
-  if (!$auth->check_database()) {
+  if (!$main::auth->check_database()) {
     $form->{title} = $locale->text('Authentification database creation');
     $form->header();
     print $form->parse_html_template('admin/check_auth_database', \%params);
@@ -138,7 +143,7 @@ sub check_auth_db_and_tables {
     exit 0;
   }
 
-  if (!$auth->check_tables()) {
+  if (!$main::auth->check_tables()) {
     $form->{title} = $locale->text('Authentification tables creation');
     $form->header();
     print $form->parse_html_template('admin/check_auth_tables', \%params);
@@ -146,10 +151,10 @@ sub check_auth_db_and_tables {
     exit 0;
   }
 
-  if (-f $memberfile) {
+  if (-f $main::memberfile) {
     my $memberdir = "";
 
-    if ($memberfile =~ m|^.*/|) {
+    if ($main::memberfile =~ m|^.*/|) {
       $memberdir = $&;
     }
 
@@ -157,7 +162,7 @@ sub check_auth_db_and_tables {
 
     $form->{title} = $locale->text('User data migration');
     $form->header();
-    print $form->parse_html_template('admin/user_migration', { 'memberfile' => $memberfile,
+    print $form->parse_html_template('admin/user_migration', { 'memberfile' => $main::memberfile,
                                                                'backupdir'  => $backupdir });
 
     exit 0
@@ -165,19 +170,25 @@ sub check_auth_db_and_tables {
 }
 
 sub create_auth_db {
-  $auth->create_database('superuser'          => $form->{db_superuser},
+  my $form     = $main::form;
+
+  $main::auth->create_database('superuser'          => $form->{db_superuser},
                          'superuser_password' => $form->{db_superuser_password},
                          'template'           => $form->{db_template});
   login();
 }
 
 sub create_auth_tables {
-  $auth->create_tables();
-  $auth->set_session_value('rpw', $form->{rpw});
-  $auth->create_or_refresh_session();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->create_tables();
+  $main::auth->set_session_value('rpw', $form->{rpw});
+  $main::auth->create_or_refresh_session();
 
-  if (!-f $memberfile) {
+  if (!-f $main::memberfile) {
     # New installation -- create a standard group with full access
+    my %members;
     my $group = {
       'name'        => $locale->text('Full Access'),
       'description' => $locale->text('Full access to all functions'),
@@ -185,18 +196,21 @@ sub create_auth_tables {
       'members'     => [ map { $_->{id} } values %members ],
     };
 
-    $auth->save_group($group);
+    $main::auth->save_group($group);
   }
 
   login();
 }
 
 sub migrate_users {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $memberdir = "";
 
-  if ($memberfile =~ m|^.*/|) {
+  if ($main::memberfile =~ m|^.*/|) {
     $memberdir = $&;
   }
 
@@ -206,9 +220,9 @@ sub migrate_users {
     $form->error(sprintf($locale->text('The directory "%s" could not be created:\n%s'), $backupdir, $!));
   }
 
-  copy $memberfile, "users/member-file-migration/members";
+  copy $main::memberfile, "users/member-file-migration/members";
 
-  my $in = IO::File->new($memberfile, "r");
+  my $in = IO::File->new($main::memberfile, "r");
 
   $form->error($locale->text('Could not open the old memberfile.')) if (!$in);
 
@@ -248,8 +262,8 @@ sub migrate_users {
   map { $_->{dbpasswd} = unpack 'u', $_->{dbpasswd} } values %members;
 
   while (my ($login, $params) = each %members) {
-    $auth->save_user($login, %{ $params });
-    $auth->change_password($login, $params->{password}, 1);
+    $main::auth->save_user($login, %{ $params });
+    $main::auth->change_password($login, $params->{password}, 1);
 
     my $conf_file = "${memberdir}${login}.conf";
 
@@ -259,7 +273,7 @@ sub migrate_users {
     }
   }
 
-  unlink $memberfile;
+  unlink $main::memberfile;
 
   my @member_list = sort { lc $a->{login} cmp lc $b->{login} } values %members;
 
@@ -267,10 +281,13 @@ sub migrate_users {
   $form->header();
   print $form->parse_html_template('admin/user_migration_done', { 'MEMBERS' => \@member_list });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_standard_group_ask {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} = $locale->text('Create a standard group');
 
   $form->header();
@@ -278,9 +295,12 @@ sub create_standard_group_ask {
 }
 
 sub create_standard_group {
-  my %members = $auth->read_all_users();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my %members = $main::auth->read_all_users();
 
-  my $groups = $auth->read_groups();
+  my $groups = $main::auth->read_groups();
 
   foreach my $group (values %{$groups}) {
     if (($form->{group_id} != $group->{id})
@@ -296,7 +316,7 @@ sub create_standard_group {
     'members'     => [ map { $_->{id} } values %members ],
   };
 
-  $auth->save_group($group);
+  $main::auth->save_group($group);
 
   user_migration_complete(1);
 }
@@ -308,6 +328,9 @@ sub dont_create_standard_group {
 sub user_migration_complete {
   my $standard_group_created = shift;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} = $locale->text('User migration complete');
   $form->header();
 
@@ -315,14 +338,17 @@ sub user_migration_complete {
 }
 
 sub list_users {
-  my %members = $auth->read_all_users();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my %members = $main::auth->read_all_users();
 
   delete $members{"root login"};
 
   map { $_->{templates} =~ s|.*/||; } values %members;
 
   $form->{title}   = "Lx-Office ERP " . $locale->text('Administration');
-  $form->{LOCKED}  = -e "$userspath/nologin";
+  $form->{LOCKED}  = -e "$main::userspath/nologin";
   $form->{MEMBERS} = [ @members{sort { lc $a cmp lc $b } keys %members} ];
 
   $form->header();
@@ -331,6 +357,9 @@ sub list_users {
 
 sub add_user {
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Administration') . " / "
@@ -349,6 +378,9 @@ sub add_user {
 }
 
 sub edit_user {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
 
   $form->{title} =
       "Lx-Office ERP "
@@ -370,29 +402,32 @@ sub edit_user {
 sub edit_user_form {
   my ($myconfig) = @_;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   my @valid_dateformats = qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd);
   $form->{ALL_DATEFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{dateformat} } } @valid_dateformats ];
 
-  my @valid_numberformats = qw(1,000.00 1000.00 1.000,00 1000,00);
+  my @valid_numberformats = ('1,000.00', '1000.00', '1.000,00', '1000,00');
   $form->{ALL_NUMBERFORMATS} = [ map { { "format" => $_, "selected" => $_ eq $myconfig->{numberformat} } } @valid_numberformats ];
 
-  %countrycodes = User->country_codes;
+  my %countrycodes = User->country_codes;
   $form->{ALL_COUNTRYCODES} = [];
-  foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
+  foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
     push @{ $form->{ALL_COUNTRYCODES} }, { "value"    => $countrycode,
                                            "name"     => $countrycodes{$countrycode},
                                            "selected" => $countrycode eq $myconfig->{countrycode} };
   }
 
   # is there a templates basedir
-  if (!-d "$templates") {
-    $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
+  if (!-d "$main::templates") {
+    $form->error(sprintf($locale->text("The directory %s does not exist."), $main::templates));
   }
 
-  opendir TEMPLATEDIR, "$templates/." or $form->error("$templates : $ERRNO");
+  opendir TEMPLATEDIR, "$main::templates/." or $form->error("$main::templates : $ERRNO");
   my @all     = readdir(TEMPLATEDIR);
-  my @alldir  = sort grep { -d "$templates/$_" && !/^\.\.?$/ } @all;
-  my @allhtml = sort grep { -f "$templates/$_" && /\.html$/ } @all;
+  my @alldir  = sort grep { -d "$main::templates/$_" && !/^\.\.?$/ } @all;
+  my @allhtml = sort grep { -f "$main::templates/$_" && /\.html$/ } @all;
   closedir TEMPLATEDIR;
 
   @alldir = grep !/\.(html|tex|sty|odt|xml|txb)$/, @alldir;
@@ -404,10 +439,10 @@ sub edit_user_form {
 
   $form->{ALL_TEMPLATES} = [ map { { "name", => $_, "selected" => $_ eq $myconfig->{templates} } } @alldir ];
 
-  $lastitem = $allhtml[0];
+  my $lastitem = $allhtml[0];
   $lastitem =~ s/-.*//g;
   $form->{ALL_MASTER_TEMPLATES} = [ { "name" => $lastitem, "selected" => $lastitem eq "German" } ];
-  foreach $item (@allhtml) {
+  foreach my $item (@allhtml) {
     $item =~ s/-.*//g;
     next if ($item eq $lastitem);
 
@@ -426,8 +461,8 @@ sub edit_user_form {
   my $groups = [];
 
   if ($form->{edit}) {
-    my $user_id    = $auth->get_user_id($form->{login});
-    my $all_groups = $auth->read_groups();
+    my $user_id    = $main::auth->get_user_id($form->{login});
+    my $all_groups = $main::auth->read_groups();
 
     foreach my $group (values %{ $all_groups }) {
       push @{ $groups }, $group if (grep { $user_id == $_ } @{ $group->{members} });
@@ -436,13 +471,16 @@ sub edit_user_form {
     $groups = [ sort { lc $a->{name} cmp lc $b->{name} } @{ $groups } ];
   }
 
-  $form->{CAN_CHANGE_PASSWORD} = $auth->can_change_password();
+  $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
 
   $form->header();
   print $form->parse_html_template("admin/edit_user", { 'GROUPS' => $groups });
 }
 
 sub save_user {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{dbdriver} = 'Pg';
 
   # no spaces allowed in login name
@@ -451,7 +489,7 @@ sub save_user {
 
   # check for duplicates
   if (!$form->{edit}) {
-    my %members = $auth->read_all_users();
+    my %members = $main::auth->read_all_users();
     if ($members{$form->{login}}) {
       $form->show_generic_error($locale->text('Another user with the login #1 does already exist.', $form->{login}), 'back_button' => 1);
     }
@@ -468,20 +506,20 @@ sub save_user {
   }
 
   # is there a basedir
-  if (!-d "$templates") {
-    $form->error(sprintf($locale->text("The directory %s does not exist."), $templates));
+  if (!-d "$main::templates") {
+    $form->error(sprintf($locale->text("The directory %s does not exist."), $main::templates));
   }
 
   # add base directory to $form->{templates}
   $form->{templates} =~ s|.*/||;
-  $form->{templates} =  "$templates/$form->{templates}";
+  $form->{templates} =  "$main::templates/$form->{templates}";
 
-  $myconfig = new User($form->{login});
+  my $myconfig = new User($form->{login});
 
   $form->isblank("dbname", $locale->text('Dataset missing!'));
   $form->isblank("dbuser", $locale->text('Database User missing!'));
 
-  foreach $item (keys %{$form}) {
+  foreach my $item (keys %{$form}) {
     $myconfig->{$item} = $form->{$item};
   }
 
@@ -492,17 +530,18 @@ sub save_user {
 
   $myconfig->save_member();
 
-  if ($auth->can_change_password()
+  if ($main::auth->can_change_password()
       && defined $form->{new_password}
       && ($form->{new_password} ne '********')) {
-    $auth->change_password($form->{login}, $form->{new_password});
+    $main::auth->change_password($form->{login}, $form->{new_password});
   }
 
-  if ($webdav) {
-    @webdavdirs =
+  my ($login, $password, $newfile);
+  if ($main::webdav) {
+    my @webdavdirs =
       qw(angebote bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen);
-    foreach $directory (@webdavdirs) {
-      $file = "webdav/" . $directory . "/webdav-user";
+    foreach my $directory (@webdavdirs) {
+      my $file = "webdav/" . $directory . "/webdav-user";
       if ($form->{$directory}) {
         if (open(HTACCESS, "$file")) {
           while (<HTACCESS>) {
@@ -536,7 +575,7 @@ sub save_user {
   }
 
   $form->{templates}       =~ s|.*/||;
-  $form->{templates}       =  "${templates}/$form->{templates}";
+  $form->{templates}       =  "$main::templates/$form->{templates}";
   $form->{mastertemplates} =~ s|.*/||;
 
   # create user template directory and copy master files
@@ -548,20 +587,20 @@ sub save_user {
       umask(007);
 
       # copy templates to the directory
-      opendir TEMPLATEDIR, "$templates/." or $form - error("$templates : $ERRNO");
-      @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|odt|xml|txb)$/,
+      opendir TEMPLATEDIR, "$main::templates/." or $form->error("$main::templates : $ERRNO");
+      my @templates = grep /$form->{mastertemplates}.*?\.(html|tex|sty|odt|xml|txb)$/,
         readdir TEMPLATEDIR;
       closedir TEMPLATEDIR;
 
-      foreach $file (@templates) {
-        open(TEMP, "$templates/$file")
-          or $form->error("$templates/$file : $ERRNO");
+      foreach my $file (@templates) {
+        open(TEMP, "$main::templates/$file")
+          or $form->error("$main::templates/$file : $ERRNO");
 
         $file =~ s/\Q$form->{mastertemplates}\E-//;
         open(NEW, ">$form->{templates}/$file")
           or $form->error("$form->{templates}/$file : $ERRNO");
 
-        while ($line = <TEMP>) {
+        while (my $line = <TEMP>) {
           print NEW $line;
         }
         close(TEMP);
@@ -574,8 +613,8 @@ sub save_user {
 
   # Add new user to his groups.
   if (ref $form->{new_user_group_ids} eq 'ARRAY') {
-    my $all_groups = $auth->read_groups();
-    my %user       = $auth->read_user($form->{login});
+    my $all_groups = $main::auth->read_groups();
+    my %user       = $main::auth->read_user($form->{login});
 
     foreach my $group_id (@{ $form->{new_user_group_ids} }) {
       my $group = $all_groups->{$group_id};
@@ -583,7 +622,7 @@ sub save_user {
       next if !$group;
 
       push @{ $group->{members} }, $user{id};
-      $auth->save_group($group);
+      $main::auth->save_group($group);
     }
   }
 
@@ -592,6 +631,8 @@ sub save_user {
 }
 
 sub save_user_as_new {
+  my $form     = $main::form;
+
   $form->{login} = $form->{new_user_login};
   delete @{$form}{qw(edit new_user_login)};
 
@@ -599,15 +640,18 @@ sub save_user_as_new {
 }
 
 sub delete_user {
-  my %members   = $auth->read_all_users();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my %members   = $main::auth->read_all_users();
   my $templates = $members{$form->{login}}->{templates};
 
-  $auth->delete_user($form->{login});
+  $main::auth->delete_user($form->{login});
 
   if ($templates) {
     my $templates_in_use = 0;
 
-    foreach $login (keys %members) {
+    foreach my $login (keys %members) {
       next if $form->{login} eq $login;
       next if $members{$login}->{templates} ne $templates;
       $templates_in_use = 1;
@@ -635,6 +679,8 @@ sub login_name {
 sub get_value {
   my $line = shift;
 
+  my $form     = $main::form;
+
   my ($null, $value) = split(/=/, $line, 2);
 
   # remove comments
@@ -647,6 +693,7 @@ sub get_value {
 }
 
 sub pg_database_administration {
+  my $form     = $main::form;
 
   $form->{dbdriver} = 'Pg';
   dbselect_source();
@@ -654,6 +701,9 @@ sub pg_database_administration {
 }
 
 sub dbselect_source {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{dbport}    = '5432';
   $form->{dbuser}    = 'postgres';
   $form->{dbdefault} = 'template1';
@@ -669,6 +719,9 @@ sub dbselect_source {
 }
 
 sub test_db_connection {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{dbdriver} = 'Pg';
   User::dbconnect_vars($form, $form->{dbname});
 
@@ -685,14 +738,13 @@ sub test_db_connection {
 }
 
 sub continue {
-  call_sub($form->{"nextsub"});
-}
-
-sub back {
-  call_sub($form->{"back_nextsub"});
+  call_sub($main::form->{"nextsub"});
 }
 
 sub update_dataset {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Database Administration') . " / "
@@ -707,6 +759,9 @@ sub update_dataset {
 }
 
 sub dbupdate {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{stylesheet} = "lx-office-erp.css";
   $form->{title}      = $locale->text("Dataset upgrade");
   $form->header();
@@ -742,12 +797,15 @@ sub dbupdate {
 }
 
 sub create_dataset {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{dbsources} = join " ", map { "[${_}]" } sort User->dbsources($form);
 
   $form->{CHARTS} = [];
 
-  opendir SQLDIR, "sql/." or $form - error($ERRNO);
-  foreach $item (sort grep /-chart\.sql\z/, readdir SQLDIR) {
+  opendir SQLDIR, "sql/." or $form->error($ERRNO);
+  foreach my $item (sort grep /-chart\.sql\z/, readdir SQLDIR) {
     next if ($item eq 'Default-chart.sql');
     $item =~ s/-chart\.sql//;
     push @{ $form->{CHARTS} }, { "name"     => $item,
@@ -755,12 +813,12 @@ sub create_dataset {
   }
   closedir SQLDIR;
 
-  my $default_charset = $dbcharset;
+  my $default_charset = $main::dbcharset;
   $default_charset ||= Common::DEFAULT_CHARSET;
 
   my $cluster_encoding = User->dbclusterencoding($form);
   if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i)) {
-    if ($dbcharset !~ m/^UTF-?8$/i) {
+    if ($main::dbcharset !~ m/^UTF-?8$/i) {
       $form->show_generic_error($locale->text('The selected  PostgreSQL installation uses UTF-8 as its encoding. ' .
                                               'Therefore you have to configure Lx-Office to use UTF-8 as well.'),
                                 'back_button' => 1);
@@ -788,6 +846,9 @@ sub create_dataset {
 }
 
 sub dbcreate {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->isblank("db", $locale->text('Dataset missing!'));
 
   User->dbcreate(\%$form);
@@ -802,7 +863,10 @@ sub dbcreate {
 }
 
 sub delete_dataset {
-  @dbsources = User->dbsources_unused($form);
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my @dbsources = User->dbsources_unused($form);
   $form->error($locale->text('Nothing to delete!')) unless @dbsources;
 
   $form->{title} =
@@ -816,6 +880,8 @@ sub delete_dataset {
 }
 
 sub dbdelete {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   if (!$form->{db}) {
     $form->error($locale->text('No Dataset selected!'));
@@ -832,12 +898,15 @@ sub dbdelete {
 }
 
 sub backup_dataset {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Database Administration') . " / "
     . $locale->text('Backup Dataset');
 
-  if ("$pg_dump_exe" eq "DISABLED") {
+  if ("$main::pg_dump_exe" eq "DISABLED") {
     $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.'));
   }
 
@@ -854,14 +923,17 @@ sub backup_dataset {
 }
 
 sub backup_dataset_start {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Database Administration') . " / "
     . $locale->text('Backup Dataset');
 
-  $pg_dump_exe ||= "pg_dump";
+  $main::pg_dump_exe ||= "pg_dump";
 
-  if ("$pg_dump_exe" eq "DISABLED") {
+  if ("$main::pg_dump_exe" eq "DISABLED") {
     $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.'));
   }
 
@@ -887,7 +959,7 @@ sub backup_dataset_start {
   push @args, ("-p", $form->{dbport}) if ($form->{dbport});
   push @args, $form->{dbname};
 
-  my $cmd  = "${pg_dump_exe} " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
+  my $cmd  = "$main::pg_dump_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
   my $name = "dataset_backup_$form->{dbname}_" . strftime("%Y%m%d", localtime()) . ".tar";
 
   if ($form->{destination} ne "email") {
@@ -926,7 +998,7 @@ sub backup_dataset_start {
 
     map { $mail->{$_} = $form->{$_} } qw(from to cc subject message);
 
-    $mail->{charset}     = $dbcharset ? $dbcharset : Common::DEFAULT_CHARSET;
+    $mail->{charset}     = $main::dbcharset ? $main::dbcharset : Common::DEFAULT_CHARSET;
     $mail->{attachments} = [ { "filename" => $tmp, "name" => $name } ];
     $mail->send();
 
@@ -944,16 +1016,19 @@ sub backup_dataset_start {
 }
 
 sub restore_dataset {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Database Administration') . " / "
     . $locale->text('Restore Dataset');
 
-  if ("$pg_restore_exe" eq "DISABLED") {
+  if ("$main::pg_restore_exe" eq "DISABLED") {
     $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.'));
   }
 
-  my $default_charset   = $dbcharset;
+  my $default_charset   = $main::dbcharset;
   $default_charset    ||= Common::DEFAULT_CHARSET;
 
   $form->{DBENCODINGS}  = [];
@@ -969,14 +1044,17 @@ sub restore_dataset {
 }
 
 sub restore_dataset_start {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $form->{title} =
       "Lx-Office ERP "
     . $locale->text('Database Administration') . " / "
     . $locale->text('Restore Dataset');
 
-  $pg_restore_exe ||= "pg_restore";
+  $main::pg_restore_exe ||= "pg_restore";
 
-  if ("$pg_restore_exe" eq "DISABLED") {
+  if ("$main::pg_restore_exe" eq "DISABLED") {
     $form->error($locale->text('Database backups and restorations are disabled in lx-erp.conf.'));
   }
 
@@ -1063,7 +1141,7 @@ sub restore_dataset_start {
   push @args, ("-p", $form->{dbport}) if ($form->{dbport});
   push @args, $tmp;
 
-  my $cmd = "${pg_restore_exe} " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
+  my $cmd = "$main::pg_restore_exe " . join(" ", map { s/\\/\\\\/g; s/\"/\\\"/g; $_ } @args);
 
   my $in = IO::File->new("$cmd 2>&1 |");
 
@@ -1074,7 +1152,7 @@ sub restore_dataset_start {
     $form->error($locale->text('The pg_restore process could not be started.'));
   }
 
-  $AUTOFLUSH = 1;
+  $English::AUTOFLUSH = 1;
 
   $form->header();
   print $form->parse_html_template("admin/restore_dataset_start_header");
@@ -1092,8 +1170,10 @@ sub restore_dataset_start {
 }
 
 sub unlock_system {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  unlink "$userspath/nologin";
+  unlink "$main::userspath/nologin";
 
   $form->{callback} = "admin.pl?action=list_users";
 
@@ -1102,8 +1182,10 @@ sub unlock_system {
 }
 
 sub lock_system {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  open(FH, ">$userspath/nologin")
+  open(FH, ">$main::userspath/nologin")
     or $form->error($locale->text('Cannot create Lock!'));
   close(FH);
 
@@ -1114,40 +1196,49 @@ sub lock_system {
 }
 
 sub yes {
-  call_sub($form->{yes_nextsub});
+  call_sub($main::form->{yes_nextsub});
 }
 
 sub no {
-  call_sub($form->{no_nextsub});
+  call_sub($main::form->{no_nextsub});
 }
 
 sub add {
-  call_sub($form->{add_nextsub});
+  call_sub($main::form->{add_nextsub});
 }
 
 sub edit {
+  my $form     = $main::form;
+
   $form->{edit_nextsub} ||= 'edit_user';
 
   call_sub($form->{edit_nextsub});
 }
 
 sub delete {
+  my $form     = $main::form;
+
   $form->{delete_nextsub} ||= 'delete_user';
 
   call_sub($form->{delete_nextsub});
 }
 
 sub save {
+  my $form     = $main::form;
+
   $form->{save_nextsub} ||= 'save_user';
 
   call_sub($form->{save_nextsub});
 }
 
 sub back {
-  call_sub($form->{back_nextsub});
+  call_sub($main::form->{back_nextsub});
 }
 
 sub dispatcher {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   foreach my $action (qw(create_standard_group dont_create_standard_group
                          save_user delete_user save_user_as_new)) {
     if ($form->{"action_${action}"}) {
index d84e2e5..069fa69 100644 (file)
 
 use List::MoreUtils qw(uniq);
 
+use strict;
+
 sub edit_groups {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  my @groups = sort { lc $a->{name} cmp lc $b->{name} } values %{ $auth->read_groups() };
+  my @groups = sort { lc $a->{name} cmp lc $b->{name} } values %{ $main::auth->read_groups() };
 
   $form->header();
   print $form->parse_html_template("admin/edit_groups", { 'GROUPS'     => \@groups,
                                                           'num_groups' => scalar @groups });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   delete $form->{group_id};
   $form->{message} = $locale->text("The group has been added.");
 
   save_group();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->isblank('name', $locale->text('The group name is missing.'));
 
-  my $groups = $auth->read_groups();
+  my $groups = $main::auth->read_groups();
 
   foreach my $group (values %{$groups}) {
     if (($form->{group_id} != $group->{id})
@@ -88,7 +98,7 @@ sub save_group {
 
   my $is_new = !$form->{group_id};
 
-  $auth->save_group($group);
+  $main::auth->save_group($group);
 
   $form->{message} ||= $locale->text('The group has been saved.');
 
@@ -99,21 +109,24 @@ sub save_group {
     edit_group();
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  my $groups = $auth->read_groups();
+  my $groups = $main::auth->read_groups();
 
   if (!$form->{group_id} || !$groups->{$form->{group_id}}) {
     $form->show_generic_error($locale->text("No group has been selected, or the group does not exist anymore."));
   }
 
-  $group = $groups->{$form->{group_id}};
+  my $group = $groups->{$form->{group_id}};
 
-  my %all_users   = $auth->read_all_users();
+  my %all_users   = $main::auth->read_all_users();
   my %users_by_id = map { $_->{id} => $_ } values %all_users;
 
   my @members     = uniq sort { lc $a->{login} cmp lc $b->{login} } @users_by_id{ @{ $group->{members} } };
@@ -136,20 +149,23 @@ sub edit_group {
                                                          "name"               => $group->{name},
                                                          "description"        => $group->{description} });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  my $groups = $auth->read_groups();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my $groups = $main::auth->read_groups();
 
   if (!$form->{group_id} || !$groups->{$form->{group_id}}) {
     $form->show_generic_error($locale->text("No group has been selected, or the group does not exist anymore."));
   }
 
   if ($form->{confirmed}) {
-    $auth->delete_group($form->{"group_id"});
+    $main::auth->delete_group($form->{"group_id"});
 
     $form->{message} = $locale->text("The group has been deleted.");
     edit_groups();
@@ -160,58 +176,67 @@ sub delete_group {
     print $form->parse_html_template("admin/delete_group_confirm", $groups->{$form->{group_id}});
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_to_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->isblank('user_id_not_in_group', $locale->text('No user has been selected.'));
 
-  my $groups = $auth->read_groups();
+  my $groups = $main::auth->read_groups();
 
   if (!$form->{group_id} || !$groups->{$form->{group_id}}) {
     $form->show_generic_error($locale->text('No group has been selected, or the group does not exist anymore.'));
   }
 
-  $group = $groups->{$form->{group_id}};
+  my $group = $groups->{$form->{group_id}};
   $group->{members} = [ uniq @{ $group->{members} }, $form->{user_id_not_in_group} ];
 
-  $auth->save_group($group);
+  $main::auth->save_group($group);
 
   $form->{message} = $locale->text('The user has been added to this group.');
   edit_group();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub remove_from_group {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->isblank('user_id_in_group', $locale->text('No user has been selected.'));
 
-  my $groups = $auth->read_groups();
+  my $groups = $main::auth->read_groups();
 
   if (!$form->{group_id} || !$groups->{$form->{group_id}}) {
     $form->show_generic_error($locale->text('No group has been selected, or the group does not exist anymore.'));
   }
 
-  $group            = $groups->{$form->{group_id}};
+  my $group            = $groups->{$form->{group_id}};
   $group->{members} = [ uniq grep { $_ ne $form->{user_id_in_group} } @{ $group->{members} } ];
 
-  $auth->save_group($group);
+  $main::auth->save_group($group);
 
   $form->{message} = $locale->text('The user has been removed from this group.');
   edit_group();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_group_membership {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  my %users  = $auth->read_all_users();
-  my $groups = $auth->read_groups();
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  my %users  = $main::auth->read_all_users();
+  my $groups = $main::auth->read_groups();
   $groups    = [ sort { lc $a->{name} cmp lc $b->{name} } values %{ $groups } ];
 
   my @headings = map { { 'title' => $_ } } map { $_->{name} } @{ $groups };
@@ -245,14 +270,17 @@ sub edit_group_membership {
   $form->header();
   print $form->parse_html_template('admin/edit_group_membership', { 'HEADINGS' => \@headings, 'USERS' => \@rows });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_group_membership {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  my %users  = $auth->read_all_users();
-  my $groups = $auth->read_groups();
+  my %users  = $main::auth->read_all_users();
+  my $groups = $main::auth->read_groups();
 
   foreach my $group (values %{ $groups }) {
     $group->{members} = [ ];
@@ -261,14 +289,14 @@ sub save_group_membership {
       push @{ $group->{members} }, $user->{id} if ($form->{"u_$user->{id}_g_$group->{id}"});
     }
 
-    $auth->save_group($group);
+    $main::auth->save_group($group);
   }
 
   $form->{message} = $locale->text('The group memberships have been saved.');
 
   edit_groups();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index 8f380aa..27b18e4 100644 (file)
@@ -44,23 +44,28 @@ use CGI;
 
 use Data::Dumper;
 
-1;
-
 require "bin/mozilla/common.pl";
 
+use strict;
+
+1;
+
 # end of main
 
-sub add      { call_sub("add_$form->{type}"); }
-sub delete   { call_sub("delete_$form->{type}"); }
-sub save     { call_sub("save_$form->{type}"); }
-sub edit     { call_sub("edit_$form->{type}"); }
-sub continue { call_sub($form->{"nextsub"}); }
-sub save_as_new { call_sub("save_as_new_$form->{type}"); }
+sub add      { call_sub("add_$main::form->{type}"); }
+sub delete   { call_sub("delete_$main::form->{type}"); }
+sub save     { call_sub("save_$main::form->{type}"); }
+sub edit     { call_sub("edit_$main::form->{type}"); }
+sub continue { call_sub($main::form->{"nextsub"}); }
+sub save_as_new { call_sub("save_as_new_$main::form->{type}"); }
 
 sub add_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title}     = "Add";
   $form->{charttype} = "A";
@@ -71,13 +76,16 @@ sub add_account {
   &account_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
   AM->get_account(\%myconfig, \%$form);
@@ -89,13 +97,17 @@ sub edit_account {
   &account_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub account_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   if ( $form->{action} eq 'edit_account') {
     $form->{account_exists} = '1';
@@ -122,7 +134,7 @@ sub account_header {
     }
 
     # Fill in empty row for new Taxkey
-    $newtaxkey_ref = {
+    my $newtaxkey_ref = {
       id             => '',
       chart_id       => '',
       accno          => '',
@@ -182,11 +194,11 @@ sub account_header {
   }
 
   # Newaccount Folgekonto
-  if (@{ $form->{NEWACCOUNT} }) {
+  if (@{ $form->{NEWACCOUNT} || [] }) {
     if (!$form->{new_chart_valid}) {
       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
     }
-    foreach $item (@{ $form->{NEWACCOUNT} }) {
+    foreach my $item (@{ $form->{NEWACCOUNT} }) {
       if ($item->{id} == $form->{new_chart_id}) {
         $form->{selectnewaccount} .=
           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
@@ -198,8 +210,9 @@ sub account_header {
     }
   }
 
-  $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
-  %eur = (1  => "Umsatzerlöse",
+  my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
+  my %eur = (
+          1  => "Umsatzerlöse",
           2  => "sonstige Erlöse",
           3  => "Privatanteile",
           4  => "Zinserträge",
@@ -230,8 +243,8 @@ sub account_header {
           29 => "Zinsaufwand",
           30 => "Ausserordentlicher Aufwand",
           31 => "Betriebliche Steuern");
-  foreach $item (sort({ $a <=> $b } keys(%eur))) {
-    my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item}));
+  foreach my $item (sort({ $a <=> $b } keys(%eur))) {
+    my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item}));
     if ($item == $form->{pos_eur}) {
       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
     } else {
@@ -240,9 +253,10 @@ sub account_header {
 
   }
 
-  $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
+  my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
-  %bwapos = (1  => 'Umsatzerlöse',
+  my %bwapos = (
+             1  => 'Umsatzerlöse',
              2  => 'Best.Verdg.FE/UE',
              3  => 'Aktiv.Eigenleistung',
              4  => 'Mat./Wareneinkauf',
@@ -264,8 +278,8 @@ sub account_header {
              33 => 'Sonst.neutr.Ertrag',
              34 => 'Verr.kalk.Kosten',
              35 => 'Steuern Eink.u.Ertr.');
-  foreach $item (sort({ $a <=> $b } keys %bwapos)) {
-    my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item}));
+  foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
+    my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item}));
     if ($item == $form->{pos_bwa}) {
       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
     } else {
@@ -275,8 +289,8 @@ sub account_header {
   }
 
 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
-  $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
-  foreach $item ((1, 2, 3, 4)) {
+  my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
+  foreach my $item ((1, 2, 3, 4)) {
     if ($item == $form->{pos_bilanz}) {
       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
     } else {
@@ -293,9 +307,9 @@ sub account_header {
 
   # preselections category
 
-  $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
+  my $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
-  %category = (
+  my %category = (
       'A'  => $locale->text('Asset'),
       'L'  => $locale->text('Liability'),
       'Q'  => $locale->text('Equity'),
@@ -303,7 +317,7 @@ sub account_header {
       'E'  => $locale->text('Expense'),
       'C'  => $locale->text('Costs'),
   );
-  foreach $item ( sort({ $a <=> $b } keys %category) ) {
+  foreach my $item ( sort({ $a <=> $b } keys %category) ) {
     if ($item eq $form->{category}) {
       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
     } else {
@@ -320,7 +334,7 @@ sub account_header {
       'H'  => $locale->text('Header'),
   );
 
-  foreach $item ( sort({ $a <=> $b } keys %charttype) ) {
+  foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
     if ($item eq $form->{charttype}) {
       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
 
@@ -338,8 +352,6 @@ sub account_header {
     ChartTypeIsAccount         => $ChartTypeIsAccount,
     select_category            => $select_category,
     select_charttype           => $select_charttype,
-    newaccount                 => $newaccount,
-    checked                    => $checked,
     select_bwa                 => $select_bwa,
     select_bilanz              => $select_bilanz,
     select_eur                 => $select_eur,
@@ -349,13 +361,16 @@ sub account_header {
   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
 
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   print qq|
 
@@ -387,13 +402,17 @@ sub form_footer {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->isblank("accno",       $locale->text('Account Number missing!'));
   $form->isblank("description", $locale->text('Account Description missing!'));
@@ -406,13 +425,17 @@ sub save_account {
     if (AM->save_account(\%myconfig, \%$form));
   $form->error($locale->text('Cannot save account!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_as_new_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("accno",       $locale->text('Account Number missing!'));
   $form->isblank("description", $locale->text('Account Description missing!'));
@@ -436,20 +459,24 @@ sub save_as_new_account {
     if (AM->save_account(\%myconfig, \%$form));
   $form->error($locale->text('Cannot save account!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{callback}     = build_std_url('action=list_account');
   my $link_edit_account = build_std_url('action=edit_account', 'callback');
 
   CA->all_accounts(\%myconfig, \%$form);
 
-  foreach $ca (@{ $form->{CA} }) {
+  foreach my $ca (@{ $form->{CA} }) {
 
     $ca->{debit}  = "";
     $ca->{credit} = "";
@@ -486,22 +513,26 @@ sub list_account {
   # Ausgabe des Templates
   print($form->parse_html_template('am/list_accounts', $parameters_ref));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 
 sub list_account_details {
 # Ajax Funktion aus list_account_details
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   my $chart_id = $form->{args};
 
   CA->all_accounts(\%myconfig, \%$form, $chart_id);
 
-  foreach $ca (@{ $form->{CA} }) {
+  foreach my $ca (@{ $form->{CA} }) {
 
     $ca->{debit}  = "&nbsp;";
     $ca->{credit} = "&nbsp;";
@@ -555,18 +586,22 @@ sub list_account_details {
 
   print $form->parse_html_template('am/list_account_details');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub delete_account {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = $locale->text('Delete Account');
 
-  foreach $id (
+  foreach my $id (
     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
     ) {
     if ($form->{id} == $form->{$id}) {
@@ -578,13 +613,15 @@ sub delete_account {
     if (AM->delete_account(\%myconfig, \%$form));
   $form->error($locale->text('Cannot delete account!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_department {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
   $form->{role}  = "P";
@@ -594,13 +631,16 @@ sub add_department {
   &department_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_department {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -609,24 +649,28 @@ sub edit_department {
   &department_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_department {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->departments(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_department";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Departments');
 
-  @column_index = qw(description cost profit);
-
+  my @column_index = qw(description cost profit);
+  my %column_header;
   $column_header{description} =
       qq|<th class=listheading width=90%>|
     . $locale->text('Description')
@@ -662,7 +706,8 @@ sub list_department {
         </tr>
 |;
 
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -671,8 +716,8 @@ sub list_department {
         <tr valign=top class=listrow$i>
 |;
 
-    $costcenter   = ($ref->{role} eq "C") ? "X" : "";
-    $profitcenter = ($ref->{role} eq "P") ? "X" : "";
+    my $costcenter   = ($ref->{role} eq "C") ? "X" : "";
+    my $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
     $column_data{description} =
       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
@@ -711,13 +756,16 @@ sub list_department {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub department_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title} = $locale->text("$form->{title} Department");
 
@@ -726,6 +774,7 @@ sub department_header {
 
   $form->{description} =~ s/\"/&quot;/g;
 
+  my ($rows, $description);
   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
     $description =
       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
@@ -734,8 +783,8 @@ sub department_header {
       qq|<input name=description size=60 value="$form->{description}">|;
   }
 
-  $costcenter   = "checked" if $form->{role} eq "C";
-  $profitcenter = "checked" if $form->{role} eq "P";
+  my $costcenter   = "checked" if $form->{role} eq "C";
+  my $profitcenter = "checked" if $form->{role} eq "P";
 
   $form->header;
 
@@ -769,36 +818,46 @@ sub department_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_department {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
   AM->save_department(\%myconfig, \%$form);
   $form->redirect($locale->text('Department saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_department {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->delete_department(\%myconfig, \%$form);
   $form->redirect($locale->text('Department deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_lead {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
 
@@ -807,13 +866,16 @@ sub add_lead {
   &lead_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_lead {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -824,24 +886,28 @@ sub edit_lead {
   $form->{orphaned} = 1;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_lead {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->lead(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_lead";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Lead');
 
-  @column_index = qw(description cost profit);
-
+  my @column_index = qw(description cost profit);
+  my %column_header;
   $column_header{description} =
       qq|<th class=listheading width=100%>|
     . $locale->text('Description')
@@ -866,7 +932,8 @@ sub list_lead {
         </tr>
 |;
 
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -875,7 +942,7 @@ sub list_lead {
         <tr valign=top class=listrow$i>
 |;
 
-       $lead = $ref->{lead};
+#      $lead = $ref->{lead};
 
     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
 
@@ -908,13 +975,16 @@ sub list_lead {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub lead_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = $locale->text("$form->{title} Lead");
 
@@ -923,7 +993,7 @@ sub lead_header {
 
   $form->{description} =~ s/\"/&quot;/g;
 
-  $description =
+  my $description =
       qq|<input name=description size=50 value="$form->{lead}">|;
 
   $form->header;
@@ -950,36 +1020,46 @@ sub lead_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_lead {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
   AM->save_lead(\%myconfig, \%$form);
   $form->redirect($locale->text('lead saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_lead {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->delete_lead(\%myconfig, \%$form);
   $form->redirect($locale->text('lead deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_business {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
 
@@ -988,11 +1068,14 @@ sub add_business {
   &business_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_business {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{title} = "Edit";
 
@@ -1003,24 +1086,28 @@ sub edit_business {
   $form->{orphaned} = 1;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_business {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->business(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_business";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Type of Business');
 
-  @column_index = qw(description discount customernumberinit);
-
+  my @column_index = qw(description discount customernumberinit);
+  my %column_header;
   $column_header{description} =
       qq|<th class=listheading width=60%>|
     . $locale->text('Description')
@@ -1056,7 +1143,8 @@ sub list_business {
         </tr>
 |;
 
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -1065,10 +1153,8 @@ sub list_business {
         <tr valign=top class=listrow$i>
 |;
 
-    $discount =
-      $form->format_amount(\%myconfig, $ref->{discount} * 100);
-    $description =
-      $ref->{description};
+    my $discount    = $form->format_amount(\%myconfig, $ref->{discount} * 100);
+    my $description = $ref->{description};
     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
     $column_data{discount}           = qq|<td align=right>$discount</td>|;
     $column_data{customernumberinit} =
@@ -1106,13 +1192,17 @@ sub list_business {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub business_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title}    = $locale->text("$form->{title} Business");
 
@@ -1155,37 +1245,47 @@ sub business_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_business {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
   AM->save_business(\%myconfig, \%$form);
   $form->redirect($locale->text('Business saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_business {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->delete_business(\%myconfig, \%$form);
   $form->redirect($locale->text('Business deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_language {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
 
@@ -1194,13 +1294,16 @@ sub add_language {
   &language_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_language {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -1211,24 +1314,28 @@ sub edit_language {
   $form->{orphaned} = 1;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_language {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->language(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_language";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Languages');
 
-  @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
-
+  my @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
+  my %column_header;
   $column_header{description} =
       qq|<th class=listheading width=60%>|
     . $locale->text('Description')
@@ -1276,7 +1383,8 @@ sub list_language {
         </tr>
 |;
 
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -1338,13 +1446,16 @@ sub list_language {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub language_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title}    = $locale->text("$form->{title} Language");
 
@@ -1361,7 +1472,7 @@ sub language_header {
   my $numberformat =
     qq|<option value="">| . $locale->text("use program settings") .
     qq|</option>|;
-  foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
+  foreach my $item (('1,000.00', '1000.00', '1.000,00', '1000,00')) {
     $numberformat .=
       ($item eq $form->{output_numberformat})
       ? "<option selected>$item"
@@ -1372,7 +1483,7 @@ sub language_header {
   my $dateformat =
     qq|<option value="">| . $locale->text("use program settings") .
     qq|</option>|;
-  foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
+  foreach my $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
     $dateformat .=
       ($item eq $form->{output_dateformat})
       ? "<option selected>$item"
@@ -1428,13 +1539,17 @@ sub language_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_language {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Language missing!'));
   $form->isblank("template_code", $locale->text('Template Code missing!'));
@@ -1442,25 +1557,33 @@ sub save_language {
   AM->save_language(\%myconfig, \%$form);
   $form->redirect($locale->text('Language saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_language {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->delete_language(\%myconfig, \%$form);
   $form->redirect($locale->text('Language deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub add_buchungsgruppe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   # $locale->text("Add Buchungsgruppe")
   # $locale->text("Edit Buchungsgruppe")
@@ -1478,13 +1601,16 @@ sub add_buchungsgruppe {
   &buchungsgruppe_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_buchungsgruppe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -1494,28 +1620,32 @@ sub edit_buchungsgruppe {
 
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_buchungsgruppe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->buchungsgruppe(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_buchungsgruppe";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Buchungsgruppen');
 
-  @column_index = qw(up down description inventory_accno
+  my @column_index = qw(up down description inventory_accno
                      income_accno_0 expense_accno_0
                      income_accno_1 expense_accno_1
                      income_accno_2 expense_accno_2
                      income_accno_3 expense_accno_3 );
-
+  my %column_header;
   $column_header{up} =
       qq|<th class="listheading" width="16">|
     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
@@ -1589,7 +1719,8 @@ sub list_buchungsgruppe {
   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
 
   my $row = 0;
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -1669,13 +1800,16 @@ sub list_buchungsgruppe {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub buchungsgruppe_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
 
@@ -1691,8 +1825,8 @@ sub buchungsgruppe_header {
     "IC_cogs" => $acc_expense,
     );
 
-  foreach $key (keys(%acc_type_map)) {
-    foreach $ref (@{ $form->{IC_links}{$key} }) {
+  foreach my $key (keys(%acc_type_map)) {
+    foreach my $ref (@{ $form->{IC_links}{$key} }) {
       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
     }
   }
@@ -1715,7 +1849,8 @@ sub buchungsgruppe_header {
     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
   }
 
-  if (!$eur) {
+  my $linkaccounts;
+  if (!$main::eur) {
     $linkaccounts = qq|
                <tr>
                <th align=right>| . $locale->text('Inventory') . qq|</th>
@@ -1811,49 +1946,62 @@ sub buchungsgruppe_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_buchungsgruppe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
 
   AM->save_buchungsgruppe(\%myconfig, \%$form);
   $form->redirect($locale->text('Accounting Group saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_buchungsgruppe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->delete_buchungsgruppe(\%myconfig, \%$form);
   $form->redirect($locale->text('Accounting Group deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_buchungsgruppen {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('config');
 
   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
   list_buchungsgruppe();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub add_printer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
 
@@ -1862,13 +2010,16 @@ sub add_printer {
   &printer_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_printer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -1879,24 +2030,28 @@ sub edit_printer {
   $form->{orphaned} = 1;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_printer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->printer(\%myconfig, \%$form);
 
   $form->{callback} = "am.pl?action=list_printer";
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Printer');
 
-  @column_index = qw(printer_description printer_command template_code);
-
+  my @column_index = qw(printer_description printer_command template_code);
+  my %column_header;
   $column_header{printer_description} =
       qq|<th class=listheading width=60%>|
     . $locale->text('Printer Description')
@@ -1932,7 +2087,8 @@ sub list_printer {
         </tr>
 |;
 
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -1979,13 +2135,16 @@ sub list_printer {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub printer_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title}    = $locale->text("$form->{title} Printer");
 
@@ -2029,37 +2188,48 @@ sub printer_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_printer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("printer_description", $locale->text('Description missing!'));
   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
   AM->save_printer(\%myconfig, \%$form);
   $form->redirect($locale->text('Printer saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_printer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->delete_printer(\%myconfig, \%$form);
   $form->redirect($locale->text('Printer deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Add";
 
@@ -2075,13 +2245,16 @@ sub add_payment {
   &payment_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = "Edit";
 
@@ -2094,25 +2267,29 @@ sub edit_payment {
   $form->{orphaned} = 1;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->payment(\%myconfig, \%$form);
 
   $form->{callback} = build_std_url("action=list_payment");
 
-  $callback = $form->escape($form->{callback});
+  my $callback = $form->escape($form->{callback});
 
   $form->{title} = $locale->text('Payment Terms');
 
-  @column_index = qw(up down description description_long terms_netto
+  my @column_index = qw(up down description description_long terms_netto
                      terms_skonto percent_skonto);
-
+  my %column_header;
   $column_header{up} =
       qq|<th class="listheading" align="center" valign="center" width="16">|
     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
@@ -2167,7 +2344,8 @@ sub list_payment {
   my $swap_link = build_std_url("action=swap_payment_terms");
 
   my $row = 0;
-  foreach $ref (@{ $form->{ALL} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{ALL} }) {
 
     $i++;
     $i %= 2;
@@ -2245,13 +2423,16 @@ sub list_payment {
   </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub payment_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title}    = $locale->text("$form->{title} Payment Terms");
 
@@ -2353,13 +2534,17 @@ sub payment_header {
 . qq|</li>
 </ul>|;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
   $form->{"percent_skonto"} =
@@ -2367,33 +2552,44 @@ sub save_payment {
   AM->save_payment(\%myconfig, \%$form);
   $form->redirect($locale->text('Payment Terms saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->delete_payment(\%myconfig, \%$form);
   $form->redirect($locale->text('Payment terms deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_payment_terms {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
   list_payment();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_defaults {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # get defaults for account numbers and last numbers
   AM->defaultaccounts(\%myconfig, \%$form);
@@ -2401,8 +2597,8 @@ sub edit_defaults {
 
   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
 
-  foreach $key (keys %{ $form->{IC} }) {
-    foreach $accno (sort keys %{ $form->{IC}->{$key} }) {
+  foreach my $key (keys %{ $form->{IC} }) {
+    foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
       my $array = "ACCNOS_" . uc($key);
       $form->{$array} ||= [];
 
@@ -2420,20 +2616,26 @@ sub edit_defaults {
   $form->header();
   print $form->parse_html_template('am/edit_defaults');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_defaults {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   AM->save_defaults();
 
   $form->redirect($locale->text('Defaults saved.'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _build_cfg_options {
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $idx   = shift;
   my $array = uc($idx) . 'S';
 
@@ -2448,26 +2650,30 @@ sub _build_cfg_options {
 }
 
 sub config {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
-  _build_cfg_options('numberformat', qw(1,000.00 1000.00 1.000,00 1000,00));
+  _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
-  @formats = ();
-  if ($opendocument_templates && $openofficeorg_writer_bin &&
-      $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
+  my @formats = ();
+  if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
+      $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
                      "value" => "opendocument_pdf" });
   }
-  if ($latex_templates) {
+  if ($main::latex_templates) {
     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
   }
   push(@formats, { "name" => "HTML", "value" => "html" });
-  if ($latex_templates) {
+  if ($main::latex_templates) {
     push(@formats, { "name" => $locale->text("Postscript"),
                      "value" => "postscript" });
   }
-  if ($opendocument_templates) {
+  if ($main::opendocument_templates) {
     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
                      "value" => "opendocument" });
   }
@@ -2476,7 +2682,7 @@ sub config {
     $myconfig{"template_format"} = "pdf";
   }
   $form->{TEMPLATE_FORMATS} = [];
-  foreach $item (@formats) {
+  foreach my $item (@formats) {
     push @{ $form->{TEMPLATE_FORMATS} }, {
       'name'     => $item->{name},
       'value'    => $item->{value},
@@ -2506,10 +2712,10 @@ sub config {
     };
   }
 
-  %countrycodes = User->country_codes;
+  my %countrycodes = User->country_codes;
 
   $form->{COUNTRYCODES} = [];
-  foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
+  foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
     push @{ $form->{COUNTRYCODES} }, {
       'name'     => $countrycodes{$countrycode},
       'value'    => $countrycode,
@@ -2518,7 +2724,7 @@ sub config {
   }
 
   $form->{STYLESHEETS} = [];
-  foreach $item (qw(lx-office-erp.css Win2000.css)) {
+  foreach my $item (qw(lx-office-erp.css Win2000.css)) {
     push @{ $form->{STYLESHEETS} }, {
       'name'     => $item,
       'value'    => $item,
@@ -2527,7 +2733,7 @@ sub config {
   }
 
   $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
-  $form->{CAN_CHANGE_PASSWORD} = $auth->can_change_password();
+  $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
   $form->{todo_cfg}            = { TODO->get_user_config('login' => $form->{login}) };
 
   $form->{title}               = $locale->text('Edit Preferences for #1', $form->{login});
@@ -2535,11 +2741,15 @@ sub config {
   $form->header();
   print $form->parse_html_template('am/config');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_preferences {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{stylesheet} = $form->{usestylesheet};
 
@@ -2548,13 +2758,17 @@ sub save_preferences {
   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
   $form->error($locale->text('Cannot save preferences!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub audit_control {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = $locale->text('Audit Control');
 
@@ -2596,13 +2810,17 @@ sub audit_control {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub doclose {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->closebooks(\%myconfig, \%$form);
 
@@ -2614,21 +2832,25 @@ sub doclose {
     $form->redirect($locale->text('Books are open'));
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_units {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
+  $main::auth->assert('config');
+
+  my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
   AM->units_in_use(\%myconfig, $form, $units);
   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
 
-  @languages = AM->language(\%myconfig, $form, 1);
+  my @languages = AM->language(\%myconfig, $form, 1);
 
-  @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
+  my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
 
   my $i = 1;
   foreach (@unit_list) {
@@ -2647,7 +2869,7 @@ sub edit_units {
   }
 
   $units = AM->retrieve_units(\%myconfig, $form);
-  $ddbox = AM->unit_select_data($units, undef, 1);
+  my $ddbox = AM->unit_select_data($units, undef, 1);
 
   my $updownlink = build_std_url("action=swap_units");
 
@@ -2659,17 +2881,21 @@ sub edit_units {
                                      "LANGUAGES"           => \@languages,
                                      "updownlink"          => $updownlink }));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_unit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("new_name", $locale->text("The name is missing."));
-  $units = AM->retrieve_units(\%myconfig, $form);
-  $all_units = AM->retrieve_units(\%myconfig, $form);
+  my $units = AM->retrieve_units(\%myconfig, $form);
+  my $all_units = AM->retrieve_units(\%myconfig, $form);
   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
 
   my ($base_unit, $factor);
@@ -2697,13 +2923,15 @@ sub add_unit {
 
   edit_units();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_unit_languages {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   my ($unit, $languages, $idx) = @_;
 
@@ -2717,23 +2945,27 @@ sub set_unit_languages {
          });
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_unit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
-  $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
+  my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
   AM->units_in_use(\%myconfig, $form, $old_units);
 
-  @languages = AM->language(\%myconfig, $form, 1);
+  my @languages = AM->language(\%myconfig, $form, 1);
 
-  $new_units = {};
-  @delete_units = ();
-  foreach $i (1..($form->{"rowcount"} * 1)) {
-    $old_unit = $old_units->{$form->{"old_name_$i"}};
+  my $new_units = {};
+  my @delete_units = ();
+  foreach my $i (1..($form->{"rowcount"} * 1)) {
+    my $old_unit = $old_units->{$form->{"old_name_$i"}};
     if (!$old_unit) {
       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
     }
@@ -2763,7 +2995,7 @@ sub save_unit {
     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
   }
 
-  foreach $unit (values(%{$new_units})) {
+  foreach my $unit (values(%{$new_units})) {
     next unless ($unit->{"old_name"});
     if ($unit->{"base_unit"}) {
       $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"}))
@@ -2776,11 +3008,11 @@ sub save_unit {
     }
   }
 
-  foreach $unit (values(%{$new_units})) {
+  foreach my $unit (values(%{$new_units})) {
     next if ($unit->{"unchanged_unit"});
 
     map({ $_->{"seen"} = 0; } values(%{$new_units}));
-    $new_unit = $unit;
+    my $new_unit = $unit;
     while ($new_unit->{"base_unit"}) {
       $new_unit->{"seen"} = 1;
       $new_unit = $new_units->{$new_unit->{"base_unit"}};
@@ -2797,26 +3029,33 @@ sub save_unit {
 
   edit_units();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub show_history_search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} = $locale->text("History Search");
   $form->header();
 
   print $form->parse_html_template("common/search_history");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub show_am_history {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   my $callback     = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
   $form->{order} ||= 'h.itime--1';
@@ -2875,26 +3114,32 @@ sub show_am_history {
                                    });
   $dbh->disconnect();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_units {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
 
   edit_units();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_tax {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title} =  $locale->text('Add');
 
@@ -2911,13 +3156,17 @@ sub add_tax {
   # Ausgabe des Templates
   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_tax {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title} =  $locale->text('Edit');
 
@@ -2934,13 +3183,17 @@ sub edit_tax {
   # Ausgabe des Templates
   print($form->parse_html_template('am/edit_tax', $parameters_ref));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_tax {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->taxes(\%myconfig, \%$form);
 
@@ -2952,28 +3205,38 @@ sub list_tax {
 
   $form->header();
 
+  my $parameters_ref = {
+  };
+
   # Ausgabe des Templates
   print($form->parse_html_template('am/list_tax', $parameters_ref));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _get_taxaccount_selection{
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('config');
 
   AM->get_tax_accounts(\%myconfig, \%$form);
 
   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_tax {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("rate", $locale->text('Taxrate missing!'));
   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
@@ -2992,24 +3255,31 @@ sub save_tax {
   AM->save_tax(\%myconfig, \%$form);
   $form->redirect($locale->text('Tax saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_tax {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->delete_tax(\%myconfig, \%$form);
   $form->redirect($locale->text('Tax deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_price_factor {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->{title}      = $locale->text('Add Price Factor');
   $form->{callback} ||= build_std_url('action=add_price_factor');
@@ -3018,13 +3288,17 @@ sub add_price_factor {
   $form->header();
   print $form->parse_html_template('am/edit_price_factor');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_price_factor {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title}      = $locale->text('Edit Price Factor');
   $form->{callback} ||= build_std_url('action=add_price_factor');
@@ -3037,13 +3311,17 @@ sub edit_price_factor {
   $form->header();
   print $form->parse_html_template('am/edit_price_factor');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_price_factors {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->get_all_price_factors(\%myconfig, \%$form);
 
@@ -3066,13 +3344,17 @@ sub list_price_factors {
   $form->header();
   print $form->parse_html_template('am/list_price_factors');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_price_factor {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
   $form->isblank("factor", $locale->text('Factor missing!'));
@@ -3085,13 +3367,17 @@ sub save_price_factor {
 
   $form->redirect($locale->text('Price factor saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_price_factor {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->delete_price_factor(\%myconfig, \%$form);
 
@@ -3099,24 +3385,30 @@ sub delete_price_factor {
 
   $form->redirect($locale->text('Price factor deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_price_factors {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
   list_price_factors();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_warehouse {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{title}      = $locale->text('Add Warehouse');
   $form->{callback} ||= build_std_url('action=add_warehouse');
@@ -3125,13 +3417,17 @@ sub add_warehouse {
   $form->header();
   print $form->parse_html_template('am/edit_warehouse');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_warehouse {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   AM->get_warehouse(\%myconfig, $form);
 
@@ -3144,13 +3440,17 @@ sub edit_warehouse {
   $form->header();
   print $form->parse_html_template('am/edit_warehouse');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_warehouses {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->get_all_warehouses(\%myconfig, $form);
 
@@ -3171,13 +3471,17 @@ sub list_warehouses {
   $form->header();
   print $form->parse_html_template('am/list_warehouses');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_warehouse {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank("description", $locale->text('Description missing!'));
 
@@ -3189,24 +3493,31 @@ sub save_warehouse {
 
   $form->redirect($locale->text('Warehouse saved.'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_warehouses {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('config');
 
   AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
   list_warehouses();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_warehouse {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   if (!$form->{confirmed}) {
     $form->{title} = $locale->text('Confirmation');
@@ -3224,13 +3535,17 @@ sub delete_warehouse {
     $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_bin {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   AM->save_bins(\%myconfig, $form);
 
@@ -3238,5 +3553,5 @@ sub save_bin {
 
   $form->redirect($locale->text('Bins saved.'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index a3e281f..6c6865c 100644 (file)
@@ -38,12 +38,15 @@ use SL::Form;
 use Data::Dumper;
 use List::MoreUtils qw(any);
 
-1;
-
 require "bin/mozilla/common.pl";
 
+use strict;
+
+1;
+
 # end of main
 
+my $locale   = $main::locale;
 our %translations = ('text'      => $locale->text('Free-form text'),
                      'textfield' => $locale->text('Text field'),
                      'number'    => $locale->text('Number'),
@@ -75,9 +78,12 @@ sub _is_valid_module {
 }
 
 sub list_cvar_configs {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{module} = $form->{module} || $form->{cvar_module} || 'CT';
   $form->{module} = 'CT' unless _is_valid_module($form->{module});
@@ -104,26 +110,30 @@ sub list_cvar_configs {
 
   $main::lxdebug->dump(0, "modules", \@modules);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_cvar_config {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{module} = $form->{module} || $form->{cvar_module} || 'CT';
 
   $form->{edit} = 0;
   display_cvar_config_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_cvar_config {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+
+  $main::auth->assert('config');
 
   my $config = CVar->get_config('id' => $form->{id});
 
@@ -132,13 +142,17 @@ sub edit_cvar_config {
   $form->{edit} = 1;
   display_cvar_config_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->isblank('name',        $locale->text('The name is missing.'));
   $form->isblank('description', $locale->text('The description is missing.'));
@@ -163,11 +177,14 @@ sub save {
 
   list_cvar_configs();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   CVar->delete_config('id' => $form->{id});
 
@@ -175,13 +192,17 @@ sub delete {
 
   list_cvar_configs();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_cvar_config_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   my @types = map { { 'type' => $_, 'type_tr' => $translations{$_} } } @types;
 
@@ -195,20 +216,26 @@ sub display_cvar_config_form {
   print $form->parse_html_template("amcvar/display_cvar_config_form", { TYPES   => \@types,
                                                                         MODULES => \@modules });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub swap_cvar_configs {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   AM->swap_sortkeys(\%myconfig, $form, 'custom_variable_configs');
 
   list_cvar_configs();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub dispatcher {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   foreach my $action (qw(list_cvar_configs add_cvar_config)) {
     if ($form->{"action_${action}"}) {
       call_sub($action);
index 9843f82..839fbf2 100644 (file)
@@ -36,6 +36,8 @@ use SL::Form;
 
 use Data::Dumper;
 
+use strict;
+
 1;
 
 require "bin/mozilla/common.pl";
@@ -43,43 +45,51 @@ require "bin/mozilla/common.pl";
 # end of main
 
 sub display {
-  call_sub($form->{display_nextsub});
+  call_sub($main::form->{display_nextsub});
 }
 
 sub save {
-  call_sub($form->{save_nextsub});
+  call_sub($main::form->{save_nextsub});
 }
 
 sub edit {
-  call_sub($form->{edit_nextsub});
+  call_sub($main::form->{edit_nextsub});
 }
 
 sub display_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{edit} = 0;
   display_template_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{edit} = 1;
   display_template_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('config');
 
   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
 
@@ -91,13 +101,17 @@ sub save_template {
   $form->{edit} = 0;
   display_template_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_template_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   $form->{"formname"} =~ s|.*/||;
   my $format = $form->{"format"} eq "html" ? "html" : "tex";
@@ -233,7 +247,7 @@ sub display_template_form {
   $form->header;
   print($form->parse_html_template("am/edit_templates", \%options));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index c33c913..97f2dba 100644 (file)
@@ -46,6 +46,8 @@ require "bin/mozilla/common.pl";
 require "bin/mozilla/drafts.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 1;
 
 # end of main
@@ -79,11 +81,14 @@ require "bin/mozilla/reportgenerator.pl";
 # $locale->text('Dec')
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
-  return $lxdebug->leave_sub() if (load_draft_maybe());
+  return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
   $form->{title} = "Add";
 
@@ -95,41 +100,48 @@ sub add {
   $form->{transdate} = $form->{initial_transdate};
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   $form->{title} = "Edit";
 
   &create_links;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+
+  $main::auth->assert('general_ledger');
 
   &form_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   $form->create_links("AP", \%myconfig, "vendor");
-  $taxincluded = $form->{taxincluded};
-  $duedate     = $form->{duedate};
+  my $taxincluded = $form->{taxincluded};
+  my $duedate     = $form->{duedate};
 
   IR->get_vendor(\%myconfig, \%$form);
   $form->{taxincluded} = $taxincluded;
@@ -144,7 +156,7 @@ sub create_links {
   $form->{notes} = $form->{intnotes} unless $form->{notes};
 
   # currencies
-  @curr = split(/:/, $form->{currencies});
+  my @curr = split(/:/, $form->{currencies});
   chomp $curr[0];
   $form->{defaultcurrency} = $curr[0];
 
@@ -176,15 +188,20 @@ sub create_links {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $title = $form->{title};
+  $main::auth->assert('general_ledger');
+
+  my $title = $form->{title};
   $form->{title} = $locale->text("$title Accounts Payables Transaction");
 
   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
@@ -216,12 +233,12 @@ sub form_header {
   #/show hhistory button
 
   # set option selected
-  foreach $item (qw(vendor currency department)) {
+  foreach my $item (qw(vendor currency department)) {
     $form->{"select$item"} =~ s/ selected//;
     $form->{"select$item"} =~
       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
-  $readonly = ($form->{id}) ? "readonly" : "";
+  my $readonly = ($form->{id}) ? "readonly" : "";
 
   $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
   $readonly       = ($form->{radier}) ? "" : $readonly;
@@ -241,7 +258,7 @@ sub form_header {
   $form->{creditremaining} =
     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
-  $exchangerate = qq|
+  my $exchangerate = qq|
 <input type=hidden name=forex value=$form->{forex}>
 |;
   if ($form->{currency} ne $form->{defaultcurrency}) {
@@ -260,7 +277,7 @@ sub form_header {
     }
   }
 
-  $taxincluded = "";
+  my $taxincluded = "";
 
   $taxincluded = qq|
             <tr>
@@ -270,13 +287,14 @@ sub form_header {
             </tr>
 |;
 
+  my $rows;
   if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
     $rows = 2;
   }
-  $notes =
+  my $notes =
     qq|<textarea name=notes rows=$rows cols=50 wrap=soft $readonly>$form->{notes}</textarea>|;
 
-  $department = qq|
+  my $department = qq|
               <tr>
                <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
                <td colspan=3><select name=department>$form->{selectdepartment}</select>
@@ -285,13 +303,11 @@ sub form_header {
              </tr>
 | if $form->{selectdepartment};
 
-  $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+  my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
-  $vendor =
+  my $vendor =
     ($form->{selectvendor})
-    ? qq|<select name="vendor"
-onchange="document.getElementById('update_button').click();">$form->{
-selectvendor } </select>|
+    ? qq|<select name="vendor" onchange="document.getElementById('update_button').click();">$form->{selectvendor} </select>|
     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
   my @old_project_ids = ();
@@ -357,7 +373,8 @@ selectvendor } </select>|
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2);
   if ($form->{jsscript}) {
 
     # with JavaScript Calendar
@@ -394,7 +411,7 @@ selectvendor } </select>|
   $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
 
   $form->header;
-  $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+  my $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   print qq|
 <body onLoad="$onload">
@@ -506,10 +523,10 @@ $jsscript
        </tr>
 |;
 
-  $amount  = $locale->text('Amount');
-  $project = $locale->text('Project');
+  my $amount  = $locale->text('Amount');
+  my $project = $locale->text('Project');
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
 
     # format amounts
     $form->{"amount_$i"} =
@@ -534,7 +551,7 @@ $jsscript
 
     $selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
 
-    $selectAP_amount =
+    my $selectAP_amount =
       NTI($cgi->popup_menu('-name' => "AP_amount_$i",
                            '-id' => "AP_amount_$i",
                            '-style' => 'width:400px',
@@ -545,7 +562,7 @@ $jsscript
       . $cgi->hidden('-name' => "previous_AP_amount_$i",
                      '-default' => $selected_accno_full);
 
-    $tax = qq|<td>| .
+    my $tax = qq|<td>| .
       NTI($cgi->popup_menu('-name' => "taxchart_$i",
                            '-id' => "taxchart_$i",
                            '-style' => 'width:200px',
@@ -573,7 +590,7 @@ $jsscript
     $project = "";
   }
 
-  $taxlabel =
+  my $taxlabel =
     ($form->{taxincluded})
     ? $locale->text('Tax Included')
     : $locale->text('Tax');
@@ -581,7 +598,7 @@ $jsscript
   $form->{invtotal_unformatted} = $form->{invtotal};
   $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
 
-  $APselected =
+  my $APselected =
     NTI($cgi->popup_menu('-name' => "APselected", '-id' => "APselected",
                          '-style' => 'width:400px',
                          '-values' => \@AP_values, '-labels' => \%AP_labels,
@@ -626,12 +643,14 @@ $jsscript
        </tr>
 |;
 
+  my @column_index;
   if ($form->{currency} eq $form->{defaultcurrency}) {
     @column_index = qw(datepaid source memo paid AP_paid paid_project_id);
   } else {
     @column_index = qw(datepaid source memo paid exchangerate AP_paid paid_project_id);
   }
 
+  my %column_data;
   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
@@ -652,12 +671,12 @@ $jsscript
   my $totalpaid = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     print "
         <tr>
 ";
 
-    $selectAP_paid =
+    my $selectAP_paid =
       NTI($cgi->popup_menu('-name' => "AP_paid_$i",
                            '-id' => "AP_paid_$i",
                            '-values' => \@AP_paid_values,
@@ -748,13 +767,18 @@ $jsscript
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   my $follow_ups_block;
   if ($form->{id}) {
@@ -789,8 +813,8 @@ $follow_ups_block
           qq|</label><br>|);
   }
 
-  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
-  $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
+  my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+  my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
   print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">|;
 
@@ -801,6 +825,7 @@ $follow_ups_block
 |;
     }
     # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
+    our $total_paid;
     print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
       if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ap') && !IS->is_storno(\%myconfig, $form, 'ap', $form->{id}) && (($total_paid == 0) || ($total_paid eq "")));
 
@@ -830,23 +855,29 @@ $follow_ups_block
 </html>
 ";
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub mark_as_paid {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   &mark_as_paid_common(\%myconfig,"ap");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('general_ledger');
 
   my $display = shift;
 
@@ -857,16 +888,17 @@ sub update {
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(exchangerate creditlimit creditremaining);
 
-  @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart);
-  $count = 0;
-  for $i (1 .. $form->{rowcount}) {
+  my @flds  = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart);
+  my $count = 0;
+  my (@a, $j, $totaltax);
+  for my $i (1 .. $form->{rowcount}) {
     $form->{"amount_$i"} =
       $form->parse_amount(\%myconfig, $form->{"amount_$i"});
     $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
     if ($form->{"amount_$i"}) {
       push @a, {};
       $j = $#a;
-      ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+      my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
       if ($taxkey > 1) {
         if ($form->{taxincluded}) {
           $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
@@ -907,7 +939,8 @@ sub update {
   $form->{invtotal} =
     ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
 
-  for $i (1 .. $form->{paidaccounts}) {
+  my $totalpaid;
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
       map {
         $form->{"${_}_$i"} =
@@ -932,20 +965,25 @@ sub update {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub post_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
-  for $i (1 .. $form->{paidaccounts}) {
+  our $invdate;
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -968,26 +1006,30 @@ sub post_payment {
     $form->error($locale->text('Cannot post payment!'));
 
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('general_ledger');
 
   # check if there is a vendor, invoice and due date
   $form->isblank("transdate", $locale->text("Invoice Date missing!"));
   $form->isblank("duedate",   $locale->text("Due Date missing!"));
   $form->isblank("vendor",    $locale->text('Vendor missing!'));
 
-  $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
-  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+  my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
+  my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
 
   my $zero_amount_posting = 1;
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
       $zero_amount_posting = 0;
       last;
@@ -1000,9 +1042,9 @@ sub post {
     if ($form->{currency} ne $form->{defaultcurrency});
   delete($form->{AP});
 
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -1020,14 +1062,14 @@ sub post {
   }
 
   # if old vendor ne vendor redo form
-  ($vendor) = split /--/, $form->{vendor};
+  my ($vendor) = split /--/, $form->{vendor};
   if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
     &update;
     exit;
   }
-  ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
-  ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
-  ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
+  my ($debitaccno,    $debittaxkey)    = split /--/, $form->{AP_amountselected};
+  my ($taxkey,        $NULL)           = split /--/, $form->{taxchartselected};
+  my ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
   $form->{AP}{amount_1} = $debitaccno;
   $form->{AP}{payables} = $payablesaccno;
   $form->{taxkey}       = $taxkey;
@@ -1048,13 +1090,16 @@ sub post {
   }
   $form->error($locale->text('Cannot post transaction!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   $form->{postasnew} = 1;
   # saving the history
@@ -1066,13 +1111,16 @@ sub post_as_new {
   # /saving the history
   &post;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub use_as_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
@@ -1080,13 +1128,16 @@ sub use_as_template {
   $form->{invdate} = $form->current_date(\%myconfig);
   &update;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('general_ledger');
 
   $form->{title} = $locale->text('Confirm!');
 
@@ -1100,7 +1151,7 @@ sub delete {
 <form method=post action=$form->{script}>
 |;
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
@@ -1121,15 +1172,19 @@ sub delete {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
-  if (AP->delete_transaction(\%myconfig, \%$form, $spool)) {
+  if (AP->delete_transaction(\%myconfig, \%$form, $main::spool)) {
     # saving the history
     if(!exists $form->{addition}) {
       $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
@@ -1141,17 +1196,23 @@ sub yes {
   }
   $form->error($locale->text('Cannot delete transaction!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger | vendor_invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
+  $main::auth->assert('general_ledger | vendor_invoice_edit');
 
   # setup vendor selection
   $form->all_vc(\%myconfig, "vendor", "AP");
 
+  my $vendor;
   if (@{ $form->{all_vendor} }) {
     map { $vendor .= "<option>$_->{name}--$_->{id}\n" }
       @{ $form->{all_vendor} };
@@ -1170,7 +1231,7 @@ sub search {
     } (@{ $form->{all_departments} });
   }
 
-  $department = qq|
+  my $department = qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Department') . qq|</th>
          <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
@@ -1181,7 +1242,8 @@ sub search {
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2);
   if ($form->{jsscript}) {
 
     # with JavaScript Calendar
@@ -1223,7 +1285,7 @@ sub search {
                          '-labels' => \%labels));
   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
   $form->header;
-  $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
+  my $onload = qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   print qq|
 <body onLoad="$onload">
@@ -1369,14 +1431,17 @@ $jsscript
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
@@ -1385,15 +1450,19 @@ sub create_subtotal_row {
 
   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub ap_transactions {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger | vendor_invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('general_ledger | vendor_invoice_edit');
 
   ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
 
@@ -1482,7 +1551,7 @@ sub ap_transactions {
   $form->{callback} = $href .= "&sort=$form->{sort}";
 
   # escape callback for href
-  $callback = $form->escape($href);
+  my $callback = $form->escape($href);
 
   my @subtotal_columns = qw(netamount amount paid due);
 
@@ -1491,7 +1560,7 @@ sub ap_transactions {
 
   my $idx = 0;
 
-  foreach $ap (@{ $form->{AP} }) {
+  foreach my $ap (@{ $form->{AP} }) {
     $ap->{tax} = $ap->{amount} - $ap->{netamount};
     $ap->{due} = $ap->{amount} - $ap->{paid};
 
@@ -1545,13 +1614,17 @@ sub ap_transactions {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub storno {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
   if (IS->has_storno(\%myconfig, $form, 'ap')) {
     $form->{title} = $locale->text("Cancel Accounts Payables Transaction");
@@ -1570,5 +1643,5 @@ sub storno {
 
   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index f506cd9..a893750 100644 (file)
@@ -40,20 +40,13 @@ use SL::IS;
 use SL::PE;
 use SL::ReportGenerator;
 
-# use strict;
-#use warnings;
-
-# imports
-our ($cgi, $form, $lxdebug, $locale, %myconfig);
-
 require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
 require "bin/mozilla/drafts.pl";
 require "bin/mozilla/reportgenerator.pl";
 
-1;
-
-# end of main
+use strict;
+#use warnings;
 
 # this is for our long dates
 # $locale->text('January')
@@ -83,12 +76,17 @@ require "bin/mozilla/reportgenerator.pl";
 # $locale->text('Nov')
 # $locale->text('Dec')
 
+my $totalpaid;
+
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
-  return $lxdebug->leave_sub() if (load_draft_maybe());
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
   # saving the history
   if(!exists $form->{addition} && ($form->{id} ne "")) {
@@ -106,13 +104,15 @@ sub add {
   &create_links;
   $form->{transdate} = $form->{initial_transdate};
   &display_form;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
 
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
@@ -123,24 +123,29 @@ sub edit {
   &create_links;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
 
   &form_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my ($duedate, $taxincluded, @curr);
 
@@ -203,13 +208,18 @@ sub create_links {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my ($title, $readonly, $exchangerate, $rows);
   my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
@@ -798,13 +808,18 @@ $jsscript
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my ($transdate, $closedto);
 
@@ -849,7 +864,7 @@ $follow_ups_block
 
   # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
   print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
-    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($total_paid == 0) || ($total_paid eq "")));
+    if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq "")));
 
   if ($form->{id}) {
     if ($form->{radier}) {
@@ -897,27 +912,33 @@ $follow_ups_block
 </html>
 ";
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub mark_as_paid {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   &mark_as_paid_common(\%myconfig,"ar");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my $display = shift;
 
-  my ($totaltax, $exchangerate, $totalpaid);
+  my ($totaltax, $exchangerate);
 
   $form->{invtotal} = 0;
 
@@ -1001,16 +1022,20 @@ sub update {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 #
 # ToDO: fix $closedto and $invdate
 #
 sub post_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
@@ -1035,21 +1060,27 @@ sub post_payment {
   $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
   $form->error($locale->text('Cannot post payment!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _post {
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
 
   # inline post
   post(1);
 }
 
 sub post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my ($inline) = @_;
 
@@ -1098,7 +1129,7 @@ sub post {
   $form->{AR}{receivables} = $form->{ARselected};
   $form->{storno}          = 0;
 
-  $lxdebug->message(0, $form->{amount});
+  $main::lxdebug->message(0, $form->{amount});
   $form->{id} = 0 if $form->{postasnew};
   $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
 
@@ -1113,13 +1144,16 @@ sub post {
 
   $form->redirect($locale->text('Transaction posted!')) unless $inline;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{postasnew} = 1;
   # saving the history
@@ -1131,13 +1165,16 @@ sub post_as_new {
   # /saving the history
   &post;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub use_as_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
@@ -1145,13 +1182,16 @@ sub use_as_template {
   $form->{invdate} = $form->current_date(\%myconfig);
   &update;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Confirm!');
 
@@ -1186,13 +1226,17 @@ sub delete {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if (AR->delete_transaction(\%myconfig, \%$form)) {
     # saving the history
@@ -1206,13 +1250,18 @@ sub yes {
   }
   $form->error($locale->text('Cannot delete transaction!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger | invoice_edit');
 
-  $auth->assert('general_ledger | invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my ($customer, $department);
   my ($jsscript, $button1, $button2, $onload);
@@ -1458,14 +1507,17 @@ $jsscript
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
@@ -1474,15 +1526,19 @@ sub create_subtotal_row {
 
   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub ar_transactions {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger | invoice_edit');
 
-  $auth->assert('general_ledger | invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my ($callback, $href, @columns);
 
@@ -1661,13 +1717,17 @@ sub ar_transactions {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub storno {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # don't cancel cancelled transactions
   if (IS->has_storno(\%myconfig, $form, 'ar')) {
@@ -1687,5 +1747,7 @@ sub storno {
 
   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
+
+1;
index 1ed40a7..7612166 100644 (file)
 
 use SL::Projects;
 
+use strict;
+
 # any custom scripts for this one
 if (-f "bin/mozilla/custom_arap.pl") {
   eval { require "bin/mozilla/custom_arap.pl"; };
 }
-if (-f "bin/mozilla/$form->{login}_arap.pl") {
-  eval { require "bin/mozilla/$form->{login}_arap.pl"; };
+if (-f "bin/mozilla/$main::form->{login}_arap.pl") {
+  eval { require "bin/mozilla/$main::form->{login}_arap.pl"; };
 }
 
 1;
@@ -47,9 +49,13 @@ require "bin/mozilla/common.pl";
 # end of main
 
 sub check_name {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('general_ledger               | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
+  $main::auth->assert('general_ledger               | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | cash         |' .
                 'purchase_delivery_order_edit | sales_delivery_order_edit');
 
@@ -113,14 +119,14 @@ sub check_name {
         # name is not on file
         # $locale->text('Customer not on file or locked!')
         # $locale->text('Vendor not on file or locked!')
-        $msg = ucfirst $name . " not on file or locked!";
+        my $msg = ucfirst $name . " not on file or locked!";
         $form->error($locale->text($msg));
       }
     }
   }
   $form->language_payment(\%myconfig);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $i;
 }
@@ -129,16 +135,20 @@ sub check_name {
 # $locale->text('Vendor not on file!')
 
 sub select_name {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
 
   my ($table) = @_;
 
-  @column_index = qw(ndx name address);
+  my @column_index = qw(ndx name address);
 
-  $label             = ucfirst $table;
+  my $label             = ucfirst $table;
+  my %column_data;
   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
   $column_data{name} =
     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
@@ -148,7 +158,7 @@ sub select_name {
   # list items with radio button on a form
   $form->header;
 
-  $title = $locale->text('Select from one of the names below');
+  my $title = $locale->text('Select from one of the names below');
 
   print qq|
 <body>
@@ -172,8 +182,9 @@ sub select_name {
 |;
 
   my $i = 0;
-  foreach $ref (@{ $form->{name_list} }) {
-    $checked = ($i++) ? "" : "checked";
+  my $j;
+  foreach my $ref (@{ $form->{name_list} }) {
+    my $checked = ($i++) ? "" : "checked";
 
     $ref->{name} =~ s/\"/&quot;/g;
 
@@ -216,7 +227,7 @@ sub select_name {
   map { delete $form->{$_} } qw(action name_list header);
 
   # save all other form variables
-  foreach $key (keys %${form}) {
+  foreach my $key (keys %${form}) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
@@ -235,19 +246,22 @@ sub select_name {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub name_selected {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
+  $main::auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash');
 
   # replace the variable with the one checked
 
   # index for new item
-  $i = $form->{ndx};
+  my $i = $form->{ndx};
 
   $form->{ $form->{vc} }    = $form->{"new_name_$i"};
   $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
@@ -266,18 +280,21 @@ sub name_selected {
 
   &update(1);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_project {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash         | report');
 
   my $nextsub = shift || 'update';
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     my $suffix = $i ? "_$i" : "";
     my $prefix = $i ? "" : "global";
     $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
@@ -287,6 +304,7 @@ sub check_project {
         # get new project
         $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
         my %params             = map { $_ => $form->{$_} } qw(projectnumber description active);
+        my $rows;
         if (($rows = Projects->search_projects(%params)) > 1) {
 
           # check form->{project_list} how many there are
@@ -310,19 +328,24 @@ sub check_project {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub select_project {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
+  $main::auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash         | report');
 
   my ($is_global, $nextsub) = @_;
 
-  @column_index = qw(ndx projectnumber description);
+  my @column_index = qw(ndx projectnumber description);
 
+  my %column_data;
   $column_data{ndx}           = qq|<th>&nbsp;</th>|;
   $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
   $column_data{description}   =
@@ -331,7 +354,7 @@ sub select_project {
   # list items with radio button on a form
   $form->header;
 
-  $title = $locale->text('Select from one of the projects below');
+  my $title = $locale->text('Select from one of the projects below');
 
   print qq|
 <body>
@@ -357,8 +380,9 @@ sub select_project {
 |;
 
   my $i = 0;
-  foreach $ref (@{ $form->{project_list} }) {
-    $checked = ($i++) ? "" : "checked";
+  my $j;
+  foreach my $ref (@{ $form->{project_list} }) {
+    my $checked = ($i++) ? "" : "checked";
 
     $ref->{name} =~ s/\"/&quot;/g;
 
@@ -401,7 +425,7 @@ sub select_project {
   map { delete $form->{$_} } qw(action project_list header update);
 
   # save all other form variables
-  foreach $key (keys %${form}) {
+  foreach my $key (keys %${form}) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
@@ -421,19 +445,21 @@ sub select_project {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub project_selected {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
+  $main::auth->assert('general_ledger         | vendor_invoice_edit  | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit | sales_quotation_edit | purchase_order_edit | cash         | report');
 
   # replace the variable with the one checked
 
   # index for new item
-  $i = $form->{ndx};
+  my $i = $form->{ndx};
 
   my $prefix = $form->{"is_global"} ? "global" : "";
   my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
@@ -455,8 +481,8 @@ sub project_selected {
 
   call_sub($nextsub);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
-sub continue       { call_sub($form->{"nextsub"}); }
+sub continue       { call_sub($main::form->{"nextsub"}); }
 
index 654a267..10acafd 100644 (file)
@@ -39,9 +39,13 @@ use List::Util qw(first);
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 # end of main
 
 sub assert_bp_access {
+  my $form     = $main::form;
+
   my %access_map = (
     'invoice'           => 'invoice_edit',
     'sales_order'       => 'sales_order_edit',
@@ -53,23 +57,29 @@ sub assert_bp_access {
   );
 
   if ($form->{type} && $access_map{$form->{type}}) {
-    $auth->assert($access_map{$form->{type}});
+    $main::auth->assert($access_map{$form->{type}});
 
   } elsif ($form->{type} eq 'packing_list') {
-    $lxdebug->message(0, "1");
-    if (!$auth->assert('sales_order_edit', 1)) {
-    $lxdebug->message(0, "2");
-      $auth->assert('invoice_edit') ;
+    $main::lxdebug->message(0, "1");
+    if (!$main::auth->assert('sales_order_edit', 1)) {
+    $main::lxdebug->message(0, "2");
+      $main::auth->assert('invoice_edit') ;
     }
-    $lxdebug->message(0, "3");
+    $main::lxdebug->message(0, "3");
 
   } else {
-    $auth->assert('DOES_NOT_EXIST');
+    $main::auth->assert('DOES_NOT_EXIST');
   }
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  my ($name, $account, $onload);
 
   assert_bp_access();
 
@@ -96,7 +106,7 @@ sub search {
   # $locale->text('Customer')
   # $locale->text('Vendor')
 
-  %label = (
+  my %label = (
        invoice =>
          { title => 'Sales Invoices', name => 'Customer', l_invnumber => 'Y' },
        packing_list =>
@@ -161,7 +171,7 @@ sub search {
         $account .= qq|
          <td colspan=3><select name=account>
 |;
-        foreach $ref (@{ $form->{accounts} }) {
+        foreach my $ref (@{ $form->{accounts} }) {
           $account .= qq|
           <option>$ref->{accno}--$ref->{description}
 |;
@@ -186,7 +196,8 @@ sub search {
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2);
   if ($form->{jsscript}) {
 
     # with JavaScript Calendar
@@ -272,17 +283,20 @@ $jsscript
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub remove {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   assert_bp_access();
 
-  $selected = 0;
+  my $selected = 0;
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->{"checked_$i"}) {
       $selected = 1;
       last;
@@ -303,7 +317,7 @@ sub remove {
 
   map { delete $form->{$_} } qw(action header);
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
   }
@@ -324,11 +338,15 @@ sub remove {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   assert_bp_access();
 
@@ -336,14 +354,18 @@ sub yes {
   $form->{callback} .= "&header=1" if $form->{callback};
 
   $form->redirect($locale->text('Removed spoolfiles!'))
-    if (BP->delete_spool(\%myconfig, \%$form, $spool));
+    if (BP->delete_spool(\%myconfig, \%$form, $main::spool));
   $form->error($locale->text('Cannot remove files!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   assert_bp_access();
 
@@ -360,11 +382,11 @@ sub print {
     $form->{callback} .= "&header=1";
   }
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->{"checked_$i"}) {
       $form->info($locale->text('Printing ... '));
 
-      if (BP->print_spool(\%myconfig, \%$form, $spool, "| $selected_printer")) {
+      if (BP->print_spool(\%myconfig, \%$form, $main::spool, "| $selected_printer")) {
         print $locale->text('done');
         $form->redirect($locale->text('Marked entries printed!'));
       }
@@ -374,11 +396,15 @@ sub print {
 
   $form->error('Nothing selected!');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_spool {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   assert_bp_access();
 
@@ -388,12 +414,13 @@ sub list_spool {
 
   BP->get_spoolfiles(\%myconfig, \%$form);
 
-  $title = $form->escape($form->{title});
-  $href  = "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
+  my $title = $form->escape($form->{title});
+  my $href  = "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
 
   $title = $form->escape($form->{title}, 1);
-  $callback =
+  my $callback =
     "bp.pl?action=list_spool&vc=$form->{vc}&type=$form->{type}&title=$title";
+  my $option;
 
   if ($form->{ $form->{vc} }) {
     $callback .= "&$form->{vc}=" . $form->escape($form->{ $form->{vc} }, 1);
@@ -446,9 +473,9 @@ sub list_spool {
       . $locale->date(\%myconfig, $form->{transdateto}, 1);
   }
 
-  $name = ucfirst $form->{vc};
+  my $name = ucfirst $form->{vc};
 
-  @columns = (transdate);
+  my @columns = qw(transdate);
   if ($form->{type} =~ /(invoice|packing_list|check|receipt)/) {
     push @columns, "invnumber";
   }
@@ -459,10 +486,13 @@ sub list_spool {
     push @columns, "quonumber";
   }
 
-  push @columns, (name, spoolfile);
-  @column_index = $form->sort_columns(@columns);
+  push @columns, qw(name spoolfile);
+  my @column_index = $form->sort_columns(@columns);
   unshift @column_index, "checked";
 
+  my %column_header;
+  my %column_data;
+
   $column_header{checked}   = "<th class=listheading>&nbsp;</th>";
   $column_header{transdate} =
       "<th><a class=listheading href=$href&sort=transdate>"
@@ -520,9 +550,11 @@ sub list_spool {
   # escape callback for href
   $callback = $form->escape($callback);
 
-  $i = 0;
+  my $i = 0;
+  my $j = 0;
+  my $spoolfile;
 
-  foreach $ref (@{ $form->{SPOOL} }) {
+  foreach my $ref (@{ $form->{SPOOL} }) {
 
     $i++;
 
@@ -531,7 +563,7 @@ sub list_spool {
     if ($ref->{invoice}) {
       $ref->{module} = ($ref->{module} eq 'ar') ? "is" : "ir";
     }
-    $module = "$ref->{module}.pl";
+    my $module = "$ref->{module}.pl";
 
     $column_data{transdate} = "<td>$ref->{transdate}&nbsp;</td>";
 
@@ -550,7 +582,7 @@ sub list_spool {
       "<td><a href=$module?action=edit&id=$ref->{id}&type=$form->{type}&callback=$callback>$ref->{quonumber}</a></td>";
     $column_data{name}      = "<td>$ref->{name}</td>";
     $column_data{spoolfile} =
-      qq|<td><a href=$spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
+      qq|<td><a href=$main::spool/$ref->{spoolfile}>$ref->{spoolfile}</a></td>
 <input type=hidden name="spoolfile_$i" value=$ref->{spoolfile}>
 |;
 
@@ -628,15 +660,17 @@ print qq|</select>|;
 }
 
 sub select_all {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   assert_bp_access();
 
   map { $form->{"checked_$_"} = 1 } (1 .. $form->{rowcount});
   &list_spool;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
-sub continue { call_sub($form->{"nextsub"}); }
+sub continue { call_sub($main::form->{"nextsub"}); }
 
index 0558ae6..66a6a6a 100644 (file)
@@ -39,6 +39,8 @@ use SL::ReportGenerator;
 
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 1;
 
 # end of main
@@ -72,13 +74,17 @@ require "bin/mozilla/reportgenerator.pl";
 # $locale->text('Dec')
 
 sub chart_of_accounts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('report');
+  $main::auth->assert('report');
 
   $form->{title} = $locale->text('Chart of Accounts');
 
-  if ($eur) {
+  if ($main::eur) {
     $form->{method} = "cash";
   }
 
@@ -137,17 +143,21 @@ sub chart_of_accounts {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('report');
+  $main::auth->assert('report');
 
   $form->{title} = $locale->text('List Transactions');
   $form->{title} .= " - " . $locale->text('Account') . " $form->{accno}";
-  $year = (localtime)[5] + 1900;
+  my $year = (localtime)[5] + 1900;
 
   # get departments
   $form->all_departments(\%myconfig);
@@ -160,24 +170,25 @@ sub list {
     } (@{ $form->{all_departments} });
   }
 
-  $department = qq|
+  my $department = qq|
         <tr>
          <th align=right nowrap>| . $locale->text('Department') . qq|</th>
          <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
        </tr>
 | if $form->{selectdepartment};
-  $accrual = ($eur) ? ""        : "checked";
-  $cash    = ($eur) ? "checked" : "";
+  my $accrual = ($main::eur) ? ""        : "checked";
+  my $cash    = ($main::eur) ? "checked" : "";
 
-  $name_1    = "fromdate";
-  $id_1      = "fromdate";
-  $value_1   = "$form->{fromdate}";
-  $trigger_1 = "trigger1";
-  $name_2    = "todate";
-  $id_2      = "todate";
-  $value_2   = "";
-  $trigger_2 = "trigger2";
+  my $name_1    = "fromdate";
+  my $id_1      = "fromdate";
+  my $value_1   = "$form->{fromdate}";
+  my $trigger_1 = "trigger1";
+  my $name_2    = "todate";
+  my $id_2      = "todate";
+  my $value_2   = "";
+  my $trigger_2 = "trigger2";
 
+  my ($button1, $button1_2, $button2, $button2_2, $jsscript);
 
   # with JavaScript Calendar
   if ($form->{jsscript}) {
@@ -225,7 +236,7 @@ sub list {
   }
   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
   $form->header;
-  $onload = qq|focus()|;
+  my $onload = qq|focus()|;
   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
 
@@ -242,7 +253,7 @@ sub list {
 <input type=hidden name=accno value=$form->{accno}>
 <input type=hidden name=description value="$form->{description}">
 <input type=hidden name=sort value=transdate>
-<input type=hidden name=eur value=$eur>
+<input type=hidden name=eur value=$main::eur>
 <input type=hidden name=accounttype value=$form->{accounttype}>
 
 <table border=0 width=100%>
@@ -263,6 +274,7 @@ sub list {
        </tr>
 |;
 
+    our $checked;
     print qq|
        <tr>
                <td align=right>
@@ -370,27 +382,35 @@ $jsscript
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub format_debit_credit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $dc = shift;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my $formatted_dc  = $form->format_amount(\%myconfig, abs($dc), 2) . ' ';
   $formatted_dc    .= ($dc > 0) ? $locale->text('Credit (one letter abbreviation)') : $locale->text('Debit (one letter abbreviation)');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $formatted_dc;
 }
 
 
 sub list_transactions {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('report');
+  $main::auth->assert('report');
 
   $form->{title} = $locale->text('Account') . " $form->{accno} - $form->{description}";
 
@@ -438,7 +458,7 @@ sub list_transactions {
         $form->{fromdate} = "1.2.$form->{year}";
 
         #this works from 1901 to 2099, 1900 and 2100 fail.
-        $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
         $form->{todate} = "$leap.2.$form->{year}";
         last SWITCH;
       };
@@ -558,7 +578,7 @@ sub list_transactions {
 
   my %column_alignment = map { $_ => 'right' } qw(debit credit);
 
-  @custom_headers = ();
+  my @custom_headers = ();
  # Zeile 1:
  push @custom_headers, [
    { 'text' => 'Letzte Buchung', },
@@ -610,7 +630,7 @@ sub list_transactions {
 
   $report->set_sort_indicator($form->{sort}, 1);
 
-  $column_defs->{balance}->{visible} = 1;
+  $column_defs{balance}->{visible} = 1;
 
   my $ml = ($form->{category} =~ /(A|E)/) ? -1 : 1;
 
@@ -706,7 +726,7 @@ sub list_transactions {
 
 
   $report->add_separator();
-  my $row = {
+  $row = {
      'transdate' => {
        'data'    => "",
        'class' => 'listtotal',
@@ -736,7 +756,7 @@ sub list_transactions {
 
   $report->add_data($row);
   my $saldo_new = format_debit_credit($form->{saldo_new});
-  my $row = {
+  $row = {
      'transdate' => {
        'data'    => "",
        'class' => 'listtotal',
@@ -769,11 +789,14 @@ sub list_transactions {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my ($totals, $columns, $column_alignment, $class) = @_;
 
@@ -783,7 +806,7 @@ sub create_subtotal_row {
 
   map { $totals->{$_} = 0 } qw(debit credit);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
index f03911c..3bc458a 100644 (file)
@@ -14,8 +14,12 @@ use SL::DBUtils;
 use SL::Form;
 use SL::MoreCommon;
 
+use strict;
+
 sub build_std_url {
-  $lxdebug->enter_sub(2);
+  $main::lxdebug->enter_sub(2);
+
+  my $form     = $main::form;
 
   my $script = $form->{script};
 
@@ -40,7 +44,7 @@ sub build_std_url {
 
   my $url = "${script}?" . join('&', @parts);
 
-  $lxdebug->leave_sub(2);
+  $main::lxdebug->leave_sub(2);
 
   return $url;
 }
@@ -48,10 +52,13 @@ sub build_std_url {
 # -------------------------------------------------------------------------
 
 sub select_part {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($callback_sub, @parts) = @_;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   my $remap_parts_id = 0;
   if (defined($parts[0]->{parts_id}) && !defined($parts[0]->{id})) {
     $remap_parts_id = 1;
@@ -89,11 +96,13 @@ sub select_part {
                                      "remap_parts_id"   => $remap_parts_id,
                                      "remap_partnumber" => $remap_partnumber });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub select_part_internal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my ($new_item, $callback_sub);
 
@@ -116,21 +125,25 @@ sub select_part_internal {
     delete $new_item->{number};
   }
 
-  my $callback_sub = $form->{callback_sub};
+  $callback_sub = $form->{callback_sub};
 
   restore_form($form->{old_form});
 
   call_sub($callback_sub, $new_item);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub part_selection_internal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $order_by  = "description";
+  my $order_by  = "description";
   $order_by  = $form->{"order_by"} if (defined($form->{"order_by"}));
-  $order_dir = 1;
+  my $order_dir = 1;
   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
 
   my %options;
@@ -147,7 +160,8 @@ sub part_selection_internal {
 
   map { $form->{$_} = $options{$_} if ($options{$_}) } qw(no_services no_assemblies assemblies click_button);
 
-  $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
+  my $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir);
+  my $onload;
 
   if (0 == scalar(@{$parts})) {
     $form->show_generic_information($locale->text("No part was found matching the search parameters."));
@@ -180,21 +194,27 @@ sub part_selection_internal {
                                                                "PARTS"  => $parts,
                                                                "onload" => $onload });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub delivery_customer_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $order_by = "name";
+  my $order_by = "name";
   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
-  $order_dir = 1;
+  my $order_dir = 1;
   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
 
-  $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
+  my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir);
   map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery}));
+
+  my $onload;
   if (0 == scalar(@{$delivery})) {
     $form->show_generic_information($locale->text("No Customer was found matching the search parameters."));
   } elsif (1 == scalar(@{$delivery})) {
@@ -224,21 +244,27 @@ sub delivery_customer_selection {
                                                                          "DELIVERY" => $delivery,
                                                                          "onload"   => $onload });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub vendor_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $order_by = "name";
+  my $order_by = "name";
   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
-  $order_dir = 1;
+  my $order_dir = 1;
   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
 
-  $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
+  my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir);
   map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor}));
+
+  my $onload;
   if (0 == scalar(@{$vendor})) {
     $form->show_generic_information($locale->text("No Vendor was found matching the search parameters."));
   } elsif (1 == scalar(@{$vendor})) {
@@ -268,19 +294,24 @@ sub vendor_selection {
                                                               "VENDOR" => $vendor,
                                                               "onload" => $onload });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub calculate_qty {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{formel} =~ s/\r\n//g;
 
   my ($variable_string, $formel) = split /###/,$form->{formel};
+  my @variable;
+  my $onload; # note! this sub is mostly called over a javascript invocation, and it's unlikey that onload is set.
 
-  foreach $item (split m/;/, $variable_string) {
+  foreach my $item (split m/;/, $variable_string) {
     next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x;
     push @variable, {
       description => $1,
@@ -307,33 +338,36 @@ sub calculate_qty {
                                                               "VARIABLES" => \@variable,
                                                               "onload"    => $onload });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub set_longdescription {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text("Enter longdescription");
   $form->header();
   print $form->parse_html_template("generic/set_longdescription");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub H {
-  return $locale->quote_special_chars('HTML', $_[0]);
+  return $main::locale->quote_special_chars('HTML', $_[0]);
 }
 
 sub Q {
-  return $locale->quote_special_chars('URL@HTML', $_[0]);
+  return $main::locale->quote_special_chars('URL@HTML', $_[0]);
 }
 
 sub E {
-  return $form->escape($_[0]);
+  return $main::form->escape($_[0]);
 }
 
 sub NTI {
@@ -344,10 +378,14 @@ sub NTI {
 }
 
 sub format_dates {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($dateformat, $longformat, @indices) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $dateformat = $myconfig{"dateformat"} unless ($dateformat);
 
   foreach my $idx (@indices) {
@@ -374,15 +412,18 @@ sub format_dates {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub reformat_numbers {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($numberformat, $places, @indices) = @_;
 
-  return $lxdebug->leave_sub()
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  return $main::lxdebug->leave_sub()
     if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
 
   foreach my $idx (@indices) {
@@ -430,13 +471,18 @@ sub reformat_numbers {
 
   $myconfig{"numberformat"} = $saved_numberformat;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub show_history {
-       $lxdebug->enter_sub();
+       $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
        my $dbh = $form->dbconnect(\%myconfig);
        my ($sort, $sortby) = split(/\-\-/, $form->{order});
   $sort =~ s/.*\.(.*)/$1/;
@@ -451,16 +497,19 @@ sub show_history {
        } );
 
        $dbh->disconnect();
-       $lxdebug->leave_sub();
+       $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub call_sub {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $name = shift;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   if (!$name) {
     $form->error($locale->text("Trying to call a sub without a name"));
   }
@@ -471,15 +520,22 @@ sub call_sub {
     $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name));
   }
 
-  &{ $name }(@_);
+  {
+    no strict "refs";
+    &{ $name }(@_);
+  }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub show_vc_details {
-       $lxdebug->enter_sub();
+       $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor";
   $form->isblank("vc_id",
@@ -494,13 +550,15 @@ sub show_vc_details {
   $form->header();
   print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" });
 
-       $lxdebug->leave_sub();
+       $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub retrieve_partunits {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount});
 
@@ -513,16 +571,19 @@ sub retrieve_partunits {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # -------------------------------------------------------------------------
 
 sub mark_as_paid_common {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($myconfig, $db_name) = @_;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   if($form->{mark_as_paid}) {
     my $dbh ||= $form->get_standard_dbh($myconfig);
     my $query = qq|UPDATE $db_name SET paid = amount WHERE id = ?|;
@@ -532,6 +593,8 @@ sub mark_as_paid_common {
 
   } else {
     my $referer = $ENV{HTTP_REFERER};
+    my $script;
+    my $callback;
     if ($referer =~ /action/) {
       $referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/;
       $script = $1;
@@ -549,21 +612,27 @@ sub mark_as_paid_common {
     print qq|</body></html>|;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub cov_selection_internal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $order_by = "name";
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  my $order_by = "name";
   $order_by = $form->{"order_by"} if (defined($form->{"order_by"}));
-  $order_dir = 1;
+  my $order_dir = 1;
   $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"}));
 
   my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer");
 
-  $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
+  my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"});
   map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs}));
+
+  my $onload;
   if (0 == scalar(@{$covs})) {
     $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type));
   } elsif (1 == scalar(@{$covs})) {
@@ -602,92 +671,107 @@ sub cov_selection_internal {
                                                               "COVS" => $covs,
                                                               "onload" => $onload }));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 # Functions to call add routines beneath different reports
 
 sub sales_invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{script} = 'is.pl';
-  $script         = "is";
+  my $script      = "is";
   $form->{type} = "invoice";
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
   require "bin/mozilla/$form->{script}";
   &add;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub ar_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{script} = 'ar.pl';
-  $script         = "ar";
+  my $script      = "ar";
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
   require "bin/mozilla/$form->{script}";
   &add;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub vendor_invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{script} = 'ir.pl';
-  $script         = "ir";
+  my $script      = "ir";
   $form->{type} = "invoice";
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
   require "bin/mozilla/$form->{script}";
   &add;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub ap_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{script} = 'ap.pl';
-  $script         = "ap";
+  my $script      = "ap";
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
   require "bin/mozilla/$form->{script}";
   &add;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub gl_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{script} = 'gl.pl';
-  $script         = "gl";
+  my $script      = "gl";
   $locale = new Locale "$myconfig{countrycode}", "$script";
 
   require "bin/mozilla/$form->{script}";
   &add;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index 35f1064..10ff706 100644 (file)
@@ -55,14 +55,18 @@ use SL::ReportGenerator;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
 1;
 
 # end of main
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{title}    = "Add";
   $form->{callback} = "$form->{script}?action=add&db=$form->{db}" unless $form->{callback};
@@ -72,13 +76,16 @@ sub add {
   &form_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
@@ -98,13 +105,17 @@ sub search {
   $form->header();
   print $form->parse_html_template('ct/search');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_names {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
@@ -236,13 +247,16 @@ sub list_names {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   # show history button
   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
@@ -259,13 +273,17 @@ sub edit {
   &form_header;
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->get_lists("employees" => "ALL_EMPLOYEES",
                    "taxzones"  => "ALL_TAXZONES");
@@ -301,26 +319,32 @@ sub form_header {
   $form->header;
   print $form->parse_html_template('ct/form_header');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
 
   print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
                                                        is_customer => $form->{db}     eq 'customer' });
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit & ' .
+  $main::auth->assert('customer_vendor_edit & ' .
                 '(general_ledger         | invoice_edit         | vendor_invoice_edit | ' .
                 ' request_quotation_edit | sales_quotation_edit | sales_order_edit    | purchase_order_edit)');
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
 #  # saving the history
 #  if(!exists $form->{addition}) {
 #      $form->{addition} = "ADD TRANSACTION";
@@ -336,19 +360,22 @@ sub add_transaction {
   }
 
   $form->{callback} = $form->escape($form->{callback}, 1);
-  $name = $form->escape("$form->{name}", 1);
+  my $name = $form->escape("$form->{name}", 1);
 
   $form->{callback} =
     "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
   $form->redirect;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_ap_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit & general_ledger');
 
-  $auth->assert('customer_vendor_edit & general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{script} = "ap.pl";
   # saving the history
@@ -359,13 +386,16 @@ sub save_and_ap_transaction {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_ar_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit & general_ledger');
+  $main::auth->assert('customer_vendor_edit & general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{script} = "ar.pl";
   # saving the history
@@ -376,16 +406,19 @@ sub save_and_ar_transaction {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   if ($form->{db} eq 'customer') {
-    $auth->assert('customer_vendor_edit & invoice_edit');
+    $main::auth->assert('customer_vendor_edit & invoice_edit');
   } else {
-    $auth->assert('customer_vendor_edit & vendor_invoice_edit');
+    $main::auth->assert('customer_vendor_edit & vendor_invoice_edit');
   }
 
   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
@@ -398,13 +431,16 @@ sub save_and_invoice {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_rfq {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit & request_quotation_edit');
+  $main::auth->assert('customer_vendor_edit & request_quotation_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{script} = "oe.pl";
   $form->{type}   = "request_quotation";
@@ -416,13 +452,16 @@ sub save_and_rfq {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_quotation {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit & sales_quotation_edit');
 
-  $auth->assert('customer_vendor_edit & sales_quotation_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{script} = "oe.pl";
   $form->{type}   = "sales_quotation";
@@ -434,16 +473,19 @@ sub save_and_quotation {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   if ($form->{db} eq 'customer') {
-    $auth->assert('customer_vendor_edit & sales_order_edit');
+    $main::auth->assert('customer_vendor_edit & sales_order_edit');
   } else {
-    $auth->assert('customer_vendor_edit & purchase_order_edit');
+    $main::auth->assert('customer_vendor_edit & purchase_order_edit');
   }
 
   $form->{script} = "oe.pl";
@@ -457,18 +499,23 @@ sub save_and_order {
   }
   # /saving the history
   &add_transaction;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_close {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $msg = ucfirst $form->{db};
-  $imsg .= " saved!";
+  my $msg = ucfirst $form->{db};
+  $msg .= " saved!";
 
   $form->isblank("name", $locale->text("Name missing!"));
+  my $rc;
   if ($form->{"db"} eq "customer") {
     $rc = CT->save_customer(\%myconfig, \%$form);
   } else {
@@ -486,16 +533,20 @@ sub save_and_close {
   # /saving the history
   $form->redirect($locale->text($msg));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
 
-  $msg = ucfirst $form->{db};
-  $imsg .= " saved!";
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  my $msg = ucfirst $form->{db};
+  $msg .= " saved!";
 
   $form->isblank("name", $locale->text("Name missing!"));
 
@@ -522,17 +573,21 @@ sub save {
   # /saving the history
   &edit;
   exit;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   CT->delete(\%myconfig, \%$form);
 
-  $msg = ucfirst $form->{db};
+  my $msg = ucfirst $form->{db};
   $msg .= " deleted!";
   # saving the history
   if(!exists $form->{addition}) {
@@ -546,70 +601,86 @@ sub delete {
   $msg = "Cannot delete $form->{db}";
   $form->error($locale->text($msg));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
 
   &form_header();
   &form_footer();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
 
   &display();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub get_contact {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   CT->get_contact(\%myconfig, \%$form);
   print $form->ajax_response_header(), join '__pjx__', map $form->{"cp_$_"},
     qw(name title givenname phone1 phone2 email abteilung fax mobile1 mobile2 satphone satfax project privatphone privatemail birthday used gender);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub get_shipto {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('customer_vendor_edit');
 
-  $auth->assert('customer_vendor_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   CT->get_shipto(\%myconfig, \%$form);
   print $form->ajax_response_header(),  join '__pjx__', map $form->{"shipto$_"},
     qw(name department_1 department_2 street zipcode city country contact phone fax email used);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub get_delivery {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   CT->get_delivery(\%myconfig, \%$form );
   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
   print $form->ajax_response_header(), $form->parse_html_template('ct/get_delivery');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_shipto {
   $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   CT->get_shipto(\%myconfig, \%$form);
 
@@ -626,7 +697,10 @@ sub delete_shipto {
 sub delete_contact {
   $main::lxdebug->enter_sub();
 
-  $auth->assert('customer_vendor_edit');
+  $main::auth->assert('customer_vendor_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   CT->get_contact(\%myconfig, \%$form);
 
@@ -640,4 +714,4 @@ sub delete_contact {
   $main::lxdebug->leave_sub();
 }
 
-sub continue { call_sub($form->{nextsub}); }
+sub continue { call_sub($main::form->{nextsub}); }
index 5f8c61e..8f0bdd8 100644 (file)
@@ -31,18 +31,24 @@ use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
 use SL::Common;
 use SL::DATEV;
 
+use strict;
+
 1;
 
 # end of main
 
 require "bin/mozilla/common.pl";
 
-sub continue { call_sub($form->{"nextsub"}); }
+sub continue { call_sub($main::form->{"nextsub"}); }
 
 sub export {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('datev_export');
+  $main::auth->assert('datev_export');
 
   $form->{title} = $locale->text("DATEX - Export Assistent");
 
@@ -123,26 +129,32 @@ sub export {
 </body>
 </html>
 |;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub export2 {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('datev_export');
+  my $form     = $main::form;
+
+  $main::auth->assert('datev_export');
 
   if ($form->{exporttype} == 0) {
     &export_bewegungsdaten();
   } else {
     &export_stammdaten();
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub export_bewegungsdaten {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('datev_export');
+  $main::auth->assert('datev_export');
 
   $form->{title} = $locale->text("DATEX - Export Assistent");
 
@@ -259,13 +271,16 @@ sub export_bewegungsdaten {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub export_stammdaten {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('datev_export');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('datev_export');
 
   $form->{title} = $locale->text("DATEX - Export Assistent");
 
@@ -323,13 +338,17 @@ sub export_stammdaten {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub export3 {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('datev_export');
+  $main::auth->assert('datev_export');
 
   DATEV::clean_temporary_directories();
 
@@ -362,13 +381,16 @@ sub export3 {
 
   print("</body></html>");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub download {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('datev_export');
+  $main::auth->assert('datev_export');
 
   my $tmp_name = Common->tmpname();
   my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
@@ -408,5 +430,5 @@ sub download {
 
   DATEV::clean_temporary_directories();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index 715c4b4..51e046c 100644 (file)
@@ -42,12 +42,18 @@ require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 require "bin/mozilla/io.pl";
 
+use strict;
+
 1;
 
 sub edit_config {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   DN->get_config(\%myconfig, \%$form);
   $form->get_lists('charts' => { 'key'       => 'ALL_CHARTS',
@@ -77,13 +83,17 @@ sub edit_config {
   $form->header();
   print $form->parse_html_template("dunning/edit_config");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('dunning_edit');
+  $main::auth->assert('dunning_edit');
 
   # setup customer selection
   $form->all_vc(\%myconfig, "customer", "AR");
@@ -101,13 +111,17 @@ sub add {
 
   print $form->parse_html_template("dunning/add");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub show_invoices {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('dunning_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('dunning_edit');
 
   DN->get_invoices(\%myconfig, \%$form);
   $form->{title} = $locale->text('Start Dunning Process');
@@ -138,13 +152,17 @@ sub show_invoices {
   $form->header();
   print $form->parse_html_template("dunning/show_invoices");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('config');
+  $main::auth->assert('config');
 
   for my $i (1 .. $form->{rowcount}) {
     if ($form->{"dunning_description_$i"} ne "") {
@@ -165,13 +183,17 @@ sub save {
   # /saving the history
   $form->redirect($locale->text('Dunning Process Config saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_dunning {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('dunning_edit');
+  $main::auth->assert('dunning_edit');
 
   my $active=1;
   my @rows = ();
@@ -200,7 +222,7 @@ sub save_dunning {
       foreach my $level (values %{ $levels }) {
         next unless scalar @{ $level };
 
-        DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool);
+        DN->save_dunning(\%myconfig, $form, $level, $main::userspath, $main::spool);
       }
     }
 
@@ -213,7 +235,7 @@ sub save_dunning {
                       "customer_id"            => $form->{"customer_id_$i"},
                       "next_dunning_config_id" => $form->{"next_dunning_config_id_$i"},
                       "email"                  => $form->{"email_$i"}, } ];
-      DN->save_dunning(\%myconfig, $form, $level, $userspath, $spool);
+      DN->save_dunning(\%myconfig, $form, $level, $main::userspath, $main::spool);
     }
   }
 
@@ -234,25 +256,32 @@ sub save_dunning {
     $form->redirect($locale->text('Dunning Process started for selected invoices!'));
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_email {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('dunning_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('dunning_edit');
 
   $form->{"title"} = $locale->text("Set eMail text");
   $form->header();
   print($form->parse_html_template("dunning/set_email"));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('dunning_edit');
+  $main::auth->assert('dunning_edit');
 
   $form->get_lists("customers"   => "ALL_CUSTOMERS",
                    "departments" => "ALL_DEPARTMENTS");
@@ -275,14 +304,19 @@ sub search {
 
   print $form->parse_html_template("dunning/search");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub show_dunning {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('dunning_edit');
+  $main::auth->assert('dunning_edit');
 
   my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber
                              transdatefrom transdateto dunningfrom dunningto notes showold);
@@ -350,7 +384,7 @@ sub show_dunning {
 
   my $i = 0;
 
-  foreach $ref (@{ $form->{DUNNINGS} }) {
+  foreach my $ref (@{ $form->{DUNNINGS} }) {
     $i++;
 
     if ($previous_dunning_id != $ref->{dunning_id}) {
@@ -396,14 +430,16 @@ sub show_dunning {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub print_dunning {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('dunning_edit');
+  my $form     = $main::form;
+
+  $main::auth->assert('dunning_edit');
 
   $form->{rowcount}     = 1;
   $form->{selected_1}   = 1;
@@ -411,13 +447,17 @@ sub print_dunning {
 
   print_multiple();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_multiple {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('dunning_edit');
+  $main::auth->assert('dunning_edit');
 
   $form->{title} = $locale->text('Print dunnings');
 
@@ -447,11 +487,11 @@ sub print_multiple {
     $form->redirect($locale->text('Could not print dunning.'));
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub continue {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }
 
 # end of main
index 7f83bf3..c69052b 100644 (file)
@@ -1,4 +1,4 @@
-# #=====================================================================
+#=====================================================================
 # LX-Office ERP
 # Copyright (C) 2004
 # Based on SQL-Ledger Version 2.1.9
@@ -46,21 +46,28 @@ require "bin/mozilla/invoice_io.pl";
 require "bin/mozilla/io.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
+my $print_post;
+
 1;
 
 # end of main
 
 sub check_do_access {
-  $auth->assert($form->{type} . '_edit');
+  $main::auth->assert($main::form->{type} . '_edit');
 }
 
 sub set_headings {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
   my ($action) = @_;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   if ($form->{type} eq 'purchase_delivery_order') {
     $form->{vc}    = 'vendor';
     $form->{title} = $action eq "edit" ? $locale->text('Edit Purchase Delivery Order') : $locale->text('Add Purchase Delivery Order');
@@ -71,14 +78,16 @@ sub set_headings {
 
   $form->{heading} = $locale->text('Delivery Order');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+
   set_headings("add");
 
   $form->{callback} = build_std_url('action=add', 'type', 'vc') unless ($form->{callback});
@@ -87,14 +96,16 @@ sub add {
   prepare_order();
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
   #/show hhistory button
@@ -111,15 +122,16 @@ sub edit {
       # reset rowcount
       undef $form->{rowcount};
       add();
-      $lxdebug->leave_sub();
+      $main::lxdebug->leave_sub();
       return;
 #     }
   } elsif (!$form->{id}) {
     add();
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
+  my ($language_id, $printer_id);
   if ($form->{print_and_save}) {
     $form->{action}   = "dispatcher";
     $form->{action_print} = "1";
@@ -140,19 +152,22 @@ sub edit {
 
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub order_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   # get customer/vendor
   $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
 
   # retrieve order/quotation
-  $form->{webdav}   = $webdav;
+  $form->{webdav}   = $main::webdav;
   $form->{jsscript} = 1;
 
   my $editing = $form->{id};
@@ -185,18 +200,21 @@ sub order_links {
 
   $form->{employee} = "$form->{employee}--$form->{employee_id}";
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub prepare_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $form->{formname} = $form->{type} unless $form->{formname};
 
   my $i = 0;
-  foreach $ref (@{ $form->{form_details} }) {
+  foreach my $ref (@{ $form->{form_details} }) {
     $form->{rowcount} = ++$i;
 
     map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
@@ -207,9 +225,9 @@ sub prepare_order {
     } else {
       $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
     }
-    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+    my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
     $dec           = length $dec;
-    $decimalplaces = ($dec > 2) ? $dec : 2;
+    my $decimalplaces = ($dec > 2) ? $dec : 2;
 
     # copy reqdate from deliverydate for invoice -> order conversion
     $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
@@ -221,14 +239,17 @@ sub prepare_order {
     $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
   $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
 
@@ -236,7 +257,7 @@ sub form_header {
   $form->{jsscript} = 1;
 
   #write Trigger
-  $jsscript = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
+  my $jsscript = Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", "reqdate", "BL", "trigger2");
 
   my @old_project_ids = ($form->{"globalproject_id"});
   map({ push(@old_project_ids, $form->{"project_id_$_"})
@@ -282,30 +303,36 @@ sub form_header {
 
   print $form->parse_html_template('do/form_header');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+
   $form->{PRINT_OPTIONS} = print_options('inline' => 1);
 
   print $form->parse_html_template('do/form_footer');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update_delivery_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   set_headings($form->{"id"} ? "edit" : "add");
 
   $form->{update} = 1;
 
+  my $payment_id;
   $payment_id = $form->{payment_id} if $form->{payment_id};
 
   check_name($form->{vc});
@@ -313,7 +340,7 @@ sub update_delivery_order {
   $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
 
   # for pricegroups
-  $i = $form->{rowcount};
+  my $i = $form->{rowcount};
 
   if (   ($form->{"partnumber_$i"} eq "")
       && ($form->{"description_$i"} eq "")
@@ -369,14 +396,18 @@ sub update_delivery_order {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $form->{vc} = $form->{type} eq 'purchase_delivery_order' ? 'vendor' : 'customer';
 
   $form->get_lists("projects"     => { "key" => "ALL_PROJECTS",
@@ -393,15 +424,20 @@ sub search {
 
   print $form->parse_html_template('do/search');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub orders {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
-  ($form->{ $form->{vc} }, $form->{"${form->{vc}}_id"}) = split(/--/, $form->{ $form->{vc} });
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
+  ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) = split(/--/, $form->{ $form->{vc} });
 
   report_generator_set_default_sort('transdate', 1);
 
@@ -474,7 +510,7 @@ sub orders {
     push @options, $locale->text('Vendor') . " : $form->{vendor}";
   }
   if ($form->{department}) {
-    ($department) = split /--/, $form->{department};
+    my ($department) = split /--/, $form->{department};
     push @options, $locale->text('Department') . " : $department";
   }
   if ($form->{donumber}) {
@@ -518,14 +554,14 @@ sub orders {
   $form->{callback} = $href .= "&sort=$form->{sort}";
 
   # escape callback for href
-  $callback = $form->escape($href);
+  my $callback = $form->escape($href);
 
   my $edit_url       = build_std_url('action=edit', 'type', 'vc');
   my $edit_order_url = build_std_url('script=oe.pl', 'type=' . ($form->{type} eq 'sales_delivery_order' ? 'sales_order' : 'purchase_order'), 'action=edit');
 
   my $idx            = 1;
 
-  foreach $dord (@{ $form->{DO} }) {
+  foreach my $dord (@{ $form->{DO} }) {
     $dord->{open}      = $dord->{closed}    ? $locale->text('No')  : $locale->text('Yes');
     $dord->{delivered} = $dord->{delivered} ? $locale->text('Yes') : $locale->text('No');
 
@@ -548,14 +584,18 @@ sub orders {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
   $form->isblank("transdate", $locale->text('Delivery Order Date missing!'));
@@ -563,7 +603,7 @@ sub save {
   $form->{donumber} =~ s/^\s*//g;
   $form->{donumber} =~ s/\s*$//g;
 
-  $msg = ucfirst $form->{vc};
+  my $msg = ucfirst $form->{vc};
   $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
 
   # $locale->text('Customer missing!');
@@ -595,14 +635,17 @@ sub save {
     update();
     exit;
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   map { delete $form->{$_} } qw(action header login password);
   my @variables = map { { 'key' => $_, 'value' => $form->{$_} } } grep { '' eq ref $form->{$_} } keys %{ $form };
 
@@ -611,14 +654,18 @@ sub delete {
 
   print $form->parse_html_template('do/delete', { 'VARIABLES' => \@variables });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_delivery_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   if (DO->delete()) {
     # saving the history
     if(!exists $form->{addition}) {
@@ -634,14 +681,18 @@ sub delete_delivery_order {
 
   $form->error($locale->text('Cannot delete delivery order!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_do_access();
-  $auth->assert($form->{type} eq 'purchase_delivery_order' ? 'vendor_invoice_edit' : 'invoice_edit');
+  $main::auth->assert($form->{type} eq 'purchase_delivery_order' ? 'vendor_invoice_edit' : 'invoice_edit');
 
   $form->{convert_from_do_ids} = $form->{id};
   $form->{deliverydate}        = $form->{transdate};
@@ -653,6 +704,7 @@ sub invoice {
 
   delete @{$form}{qw(id closed delivered)};
 
+  my ($script, $buysell);
   if ($form->{type} eq 'purchase_delivery_order') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
     $form->{script} = 'ir.pl';
@@ -666,7 +718,7 @@ sub invoice {
     $buysell        = 'buy';
   }
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"} } qw(ship qty sellprice listprice basefactor);
   }
 
@@ -688,12 +740,12 @@ sub invoice {
   prepare_invoice();
 
   # format amounts
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{"discount_$i"});
 
-    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+    my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
     $dec           = length $dec;
-    $decimalplaces = ($dec > 2) ? $dec : 2;
+    my $decimalplaces = ($dec > 2) ? $dec : 2;
 
     # copy delivery date from reqdate for order -> invoice conversion
     $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
@@ -712,14 +764,18 @@ sub invoice {
 
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoice_multi {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_do_access();
-  $auth->assert($form->{type} eq 'sales_delivery_order' ? 'invoice_edit' : 'vendor_invoice_edit');
+  $main::auth->assert($form->{type} eq 'sales_delivery_order' ? 'invoice_edit' : 'vendor_invoice_edit');
 
   my @do_ids = map { $form->{"trans_id_$_"} } grep { $form->{"multi_id_$_"} } (1..$form->{rowcount});
 
@@ -750,7 +806,7 @@ sub invoice_multi {
   $form->{closed}              = 0;
   $form->{defaultcurrency}     = $form->get_default_currency(\%myconfig);
 
-  my $buysell;
+  my ($script, $buysell);
   if ($source_type eq 'purchase_delivery_order') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
     $form->{script} = 'ir.pl';
@@ -786,14 +842,16 @@ sub invoice_multi {
   prepare_invoice();
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+
   $form->{saveasnew} = 1;
   $form->{closed}    = 0;
   $form->{delivered} = 0;
@@ -809,14 +867,16 @@ sub save_as_new {
 
   save();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub e_mail {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_do_access();
 
+  my $form     = $main::form;
+
   $form->{print_and_save} = 1;
 
   $print_post = 1;
@@ -829,20 +889,22 @@ sub e_mail {
 
   edit_e_mail();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub calculate_stock_in_out {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $i = shift;
 
   if (!$form->{"id_${i}"}) {
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return '';
   }
 
-  AM->retrieve_all_units();
+  my $all_units = AM->retrieve_all_units();
 
   my $in_out   = $form->{type} =~ /^sales/ ? 'out' : 'in';
   my $sinfo    = DO->unpack_stock_information('packed' => $form->{"stock_${in_out}_${i}"});
@@ -856,16 +918,18 @@ sub calculate_stock_in_out {
                                             'max_places'  => 2);
   $content    .= qq| <input type="button" onclick="open_stock_in_out_window('${in_out}', $i);" value="?">|;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $content;
 }
 
 sub get_basic_bin_wh_info {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $stock_info = shift;
 
+  my $form     = $main::form;
+
   foreach my $sinfo (@{ $stock_info }) {
     next unless ($sinfo->{bin_id});
 
@@ -873,11 +937,13 @@ sub get_basic_bin_wh_info {
     map { $sinfo->{"${_}_description"} = $sinfo->{"${_}description"} = $bin_info->{"${_}_description"} } qw(bin warehouse);
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub stock_in_out_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   if ($form->{in_out} eq 'out') {
     stock_out_form();
@@ -885,14 +951,16 @@ sub stock_in_out_form {
     stock_in_form();
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub redo_stock_info {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my %params    = @_;
 
+  my $form     = $main::form;
+
   my @non_empty = grep { $_->{qty} } @{ $params{stock_info} };
 
   if ($params{add_empty_row}) {
@@ -904,11 +972,14 @@ sub redo_stock_info {
 
   @{ $params{stock_info} } = @non_empty;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update_stock_in {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my $stock_info = [];
 
@@ -919,24 +990,30 @@ sub update_stock_in {
 
   display_stock_in_form($stock_info);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub stock_in_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $stock_info = DO->unpack_stock_information('packed' => $form->{stock});
 
   display_stock_in_form($stock_info);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_stock_in_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $stock_info = shift;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $form->{title} = $locale->text('Stock');
 
   my $part_info  = IC->get_basic_part_info('id' => $form->{parts_id});
@@ -956,11 +1033,14 @@ sub display_stock_in_form {
                                                          'STOCK_INFO' => $stock_info,
                                                          'PART_INFO'  => $part_info, });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_stock_in {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my $stock_info = [];
 
@@ -977,11 +1057,15 @@ sub set_stock_in {
   $form->header();
   print $form->parse_html_template('do/set_stock_in_out');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub stock_out_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Release From Stock');
 
@@ -1023,11 +1107,15 @@ sub stock_out_form {
                                                           'WHCONTENTS' => $form->{delivered} ? $stock_info : \@contents,
                                                           'PART_INFO'  => $part_info, });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_stock_out {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my $stock_info = [];
 
@@ -1061,11 +1149,15 @@ sub set_stock_out {
     print $form->parse_html_template('do/set_stock_in_out');
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_in {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if (DO->is_marked_as_delivered('id' => $form->{id})) {
     $form->show_generic_error($locale->text('The parts for this delivery order have already been transferred in.'), 'back_button' => 1);
@@ -1108,7 +1200,7 @@ sub transfer_in {
       push @{ $form->{ERRORS} }, $locale->text('The delivery order has not been marked as delivered. The warehouse contents have not changed.');
 
       update();
-      $lxdebug->leave_sub();
+      $main::lxdebug->leave_sub();
 
       exit 0;
     }
@@ -1121,11 +1213,15 @@ sub transfer_in {
 
   save();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_out {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if (DO->is_marked_as_delivered('id' => $form->{id})) {
     $form->show_generic_error($locale->text('The parts for this delivery order have already been transferred out.'), 'back_button' => 1);
@@ -1185,7 +1281,7 @@ sub transfer_out {
         $request->{ok} = $request->{sum_base_qty} <= $inv->{qty};
       }
 
-      foreach $request (values %request_map) {
+      foreach my $request (values %request_map) {
         next if ($request->{ok});
 
         my $pinfo = $part_info_map{$request->{parts_id}};
@@ -1204,7 +1300,7 @@ sub transfer_out {
       push @{ $form->{ERRORS} }, $locale->text('The delivery order has not been marked as delivered. The warehouse contents have not changed.');
 
       update();
-      $lxdebug->leave_sub();
+      $main::lxdebug->leave_sub();
 
       exit 0;
     }
@@ -1217,11 +1313,13 @@ sub transfer_out {
 
   save();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub mark_closed {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   DO->close_orders('ids' => [ $form->{id} ]);
 
@@ -1229,23 +1327,26 @@ sub mark_closed {
 
   update();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub yes {
-  call_sub($form->{yes_nextsub});
+  call_sub($main::form->{yes_nextsub});
 }
 
 sub no {
-  call_sub($form->{no_nextsub});
+  call_sub($main::form->{no_nextsub});
 }
 
 sub update {
-  call_sub($form->{update_nextsub} || $form->{nextsub} || 'update_delivery_order');
+  call_sub($main::form->{update_nextsub} || $main::form->{nextsub} || 'update_delivery_order');
 }
 
 sub dispatcher {
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   foreach my $action (qw(update ship_to print e_mail save transfer_out transfer_in mark_closed save_as_new invoice delete)) {
     if ($form->{"action_${action}"}) {
       call_sub($action);
index 3cebddb..f6cc7b6 100644 (file)
@@ -13,8 +13,14 @@ use SL::Drafts;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 sub save_draft {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if (!$form->{draft_id} && !$form->{draft_description}) {
     restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
@@ -26,7 +32,7 @@ sub save_draft {
     $form->header();
     print($form->parse_html_template("drafts/save_new"));
 
-    return $lxdebug->leave_sub();
+    return $main::lxdebug->leave_sub();
   }
 
   my ($draft_id, $draft_description) = ($form->{draft_id}, $form->{draft_description});
@@ -40,29 +46,35 @@ sub save_draft {
 
   update();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub remove_draft {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
 
   delete @{$form}{qw(draft_id draft_description)};
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub load_draft_maybe {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
+  $main::lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
 
   my ($draft_nextsub) = @_;
 
   my @drafts = Drafts->list(\%myconfig, $form);
 
-  $lxdebug->leave_sub() and return 0 unless (@drafts);
+  $main::lxdebug->leave_sub() and return 0 unless (@drafts);
 
   $draft_nextsub = "add" unless ($draft_nextsub);
 
@@ -75,13 +87,15 @@ sub load_draft_maybe {
                                      "SAVED_FORM"    => $saved_form,
                                      "draft_nextsub" => $draft_nextsub }));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return 1;
 }
 
 sub dont_load_draft {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $draft_nextsub = $form->{draft_nextsub} || "add";
 
@@ -92,11 +106,14 @@ sub dont_load_draft {
 
   call_sub($draft_nextsub);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub load_draft {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
 
@@ -104,7 +121,7 @@ sub load_draft {
     $old_form = YAML::Load($old_form);
 
     my %dont_save_vars      = map { $_ => 1 } @Drafts::dont_save;
-    my @restore_vars        = grep { !$skip_vars{$_} } keys %{ $old_form };
+    my @restore_vars        = grep { !$dont_save_vars{$_} } keys %{ $old_form };
 
     @{$form}{@restore_vars} = @{$old_form}{@restore_vars};
 
@@ -115,11 +132,14 @@ sub load_draft {
 
   update();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_drafts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   my @ids;
   foreach (keys %{$form}) {
@@ -132,11 +152,14 @@ sub delete_drafts {
 
   add();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub draft_action_dispatcher {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   if ($form->{draft_action} eq $locale->text("Skip")) {
     dont_load_draft();
@@ -145,7 +168,7 @@ sub draft_action_dispatcher {
     delete_drafts();
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index 202a9d8..1879be0 100644 (file)
@@ -5,11 +5,15 @@ use SL::ReportGenerator;
 
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 sub _collect_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $dest = shift;
 
+  my $form     = $main::form;
+
   $dest->{LINKS} = [];
 
   foreach my $i (1 .. $form->{trans_rowcount}) {
@@ -18,11 +22,15 @@ sub _collect_links {
     push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _collect_links($form);
 
@@ -43,11 +51,14 @@ sub add {
 
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $ref = FU->retrieve('id' => $form->{id});
 
@@ -65,11 +76,13 @@ sub edit {
 
   display_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   $form->get_lists("employees" => "EMPLOYEES");
 
@@ -83,11 +96,14 @@ sub display_form {
   $form->header();
   print $form->parse_html_template('fu/add_edit');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_follow_up {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->isblank('created_for_user', $locale->text('You must chose a user.'));
   $form->isblank('follow_up_date',   $locale->text('The follow-up date is missing.'));
@@ -117,11 +133,14 @@ sub save_follow_up {
 
   report();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub finish {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   if ($form->{id}) {
     my $ref = FU->retrieve('id' => $form->{id});
@@ -150,11 +169,14 @@ sub finish {
 
   report();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   if ($form->{id}) {
     my $ref = FU->retrieve('id' => $form->{id});
@@ -183,11 +205,14 @@ sub delete {
 
   report();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->get_lists("employees" => "EMPLOYEES");
 
@@ -197,11 +222,16 @@ sub search {
   $form->header();
   print $form->parse_html_template('fu/search');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done);
 
@@ -303,11 +333,13 @@ sub report {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_for_todo_list {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done);
 
@@ -338,13 +370,16 @@ sub report_for_todo_list {
                                                                        'edit_url'   => $edit_url, });
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $content;
 }
 
 sub edit_access_rights {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $access = FU->retrieve_access_rights();
 
@@ -357,11 +392,14 @@ sub edit_access_rights {
   $form->header();
   print $form->parse_html_template('fu/edit_access_rights');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_access_rights {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my %access;
 
@@ -376,26 +414,31 @@ sub save_access_rights {
   $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
   edit_access_rights();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }
 
 sub continue {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }
 
 sub save {
-  if ($form->{save_nextsub}) {
-    call_sub($form->{save_nextsub});
+  if ($main::form->{save_nextsub}) {
+    call_sub($main::form->{save_nextsub});
   } else {
     save_follow_up();
   }
 }
 
 sub dispatcher {
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   foreach my $action (qw(finish save delete)) {
     if ($form->{"action_${action}"}) {
       call_sub($action);
index 6086117..385ce80 100644 (file)
@@ -2,10 +2,15 @@ use SL::Auth;
 use SL::Form;
 use SL::GenericTranslations;
 
+use strict;
+
 sub edit_greetings {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->get_lists('languages' => 'LANGUAGES');
 
@@ -33,13 +38,16 @@ sub edit_greetings {
   $form->header();
   print $form->parse_html_template('generictranslations/edit_greetings');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_greetings {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->get_lists('languages' => 'LANGUAGES');
 
@@ -60,7 +68,7 @@ sub save_greetings {
 
   edit_greetings();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index ae476bd..731f525 100644 (file)
@@ -44,9 +44,7 @@ require "bin/mozilla/common.pl";
 require "bin/mozilla/drafts.pl";
 require "bin/mozilla/reportgenerator.pl";
 
-1;
-
-# end of main
+use strict;
 
 # this is for our long dates
 # $locale->text('January')
@@ -76,12 +74,19 @@ require "bin/mozilla/reportgenerator.pl";
 # $locale->text('Nov')
 # $locale->text('Dec')
 
+my $tax;
+my $debitlock  = 0;
+my $creditlock = 0;
+
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  return $lxdebug->leave_sub() if (load_draft_maybe());
+  return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
   $form->{title} = "Add";
 
@@ -117,14 +122,17 @@ sub add {
   $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
 
   &display_form(1);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub prepare_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   GL->transaction(\%myconfig, \%$form);
 
@@ -150,8 +158,8 @@ sub prepare_transaction {
   my $i        = 1;
   my $tax      = 0;
   my $taxaccno = "";
-  foreach $ref (@{ $form->{GL} }) {
-    $j = $i - 1;
+  foreach my $ref (@{ $form->{GL} }) {
+    my $j = $i - 1;
     if ($tax && ($ref->{accno} eq $taxaccno)) {
       $form->{"tax_$j"}      = abs($ref->{amount});
       $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
@@ -192,13 +200,16 @@ sub prepare_transaction {
     ($form->datetonum($form->{transdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   prepare_transaction();
 
@@ -210,14 +221,19 @@ sub edit {
   display_rows();
   form_footer();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   $form->{title} = $locale->text('Journal');
 
@@ -233,7 +249,7 @@ sub search {
     } (@{ $form->{all_departments} });
   }
 
-  $department = qq|
+  my $department = qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Department') . qq|</th>
          <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
@@ -257,7 +273,8 @@ sub search {
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2, $onload);
   if ($form->{jsscript}) {
 
     # with JavaScript Calendar
@@ -401,29 +418,36 @@ $jsscript
 </body>
 </html>
 |;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
 
   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub generate_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   report_generator_set_default_sort('transdate', 1);
 
@@ -541,7 +565,7 @@ sub generate_report {
   my %totals         = map { $_ => 0 } @totals_columns;
   my $idx            = 0;
 
-  foreach $ref (@{ $form->{GL} }) {
+  foreach my $ref (@{ $form->{GL} }) {
 
     my %rows;
 
@@ -647,13 +671,16 @@ sub generate_report {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{oldtransdate} = $form->{transdate};
 
@@ -663,8 +690,7 @@ sub update {
   my $credittax   = 0;
   my $debitcount  = 0;
   my $creditcount = 0;
-  $debitlock  = 0;
-  $creditlock = 0;
+  my ($debitcredit, $amount);
 
   my @flds =
     qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
@@ -713,12 +739,12 @@ sub update {
         ($form->{"debit_$i"} == 0)
         ? $form->{"credit_$i"}
         : $form->{"debit_$i"};
-      $j = $#a;
+      my $j = $#a;
       if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
         $form->{"taxchart_$i"} = "0--0.00";
         $form->{"tax_$i"}      = 0;
       }
-      ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+      my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
       if ($taxkey > 1) {
         if ($debitcredit) {
           $debittax = 1;
@@ -739,27 +765,30 @@ sub update {
     }
   }
 
-  for $i (1 .. $count) {
-    $j = $i - 1;
+  for my $i (1 .. $count) {
+    my $j = $i - 1;
     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
   }
 
-  for $i ($count + 1 .. $form->{rowcount}) {
+  for my $i ($count + 1 .. $form->{rowcount}) {
     for (@flds) { delete $form->{"${_}_$i"} }
   }
 
   $form->{rowcount} = $count + 1;
 
   &display_form;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub display_form {
   my ($init) = @_;
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   &form_header($init);
 
@@ -771,15 +800,19 @@ sub display_form {
   #   }
   &display_rows($init);
   &form_footer;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub display_rows {
   my ($init) = @_;
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $cgi      = $main::cgi;
 
   $form->{debit_1}     = 0 if !$form->{"debit_1"};
   $form->{totaldebit}  = 0;
@@ -797,7 +830,7 @@ sub display_rows {
   my %charts = ();
   my $taxchart_init;
   foreach my $item (@{ $form->{ALL_CHARTS} }) {
-    if ($item->{charttype} eq 'H'){ #falls überschrift 
+    if ($item->{charttype} eq 'H'){ #falls überschrift
       next;                         #überspringen (Bug 1150)
     }
     my $key = $item->{accno} . "--" . $item->{tax_id};
@@ -818,7 +851,8 @@ sub display_rows {
     $taxcharts{$item->{id}} = $item;
   }
 
-  for $i (1 .. $form->{rowcount}) {
+  my ($source, $memo, $source_hidden, $memo_hidden);
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->{show_details}) {
       $source = qq|
       <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
@@ -850,7 +884,7 @@ sub display_rows {
     $selected_accno      = '' if ($init);
     $selected_taxchart ||= $taxchart_init;
 
-    $accno = qq|<td>| .
+    my $accno = qq|<td>| .
       NTI($cgi->popup_menu('-name' => "accno_$i",
                            '-id' => "accno_$i",
                            '-onChange' => "setTaxkey($i)",
@@ -870,6 +904,7 @@ sub display_rows {
                            '-default' => $selected_taxchart))
       . qq|</td>|;
 
+    my ($fx_transaction, $checked);
     if ($init) {
       if ($form->{transfer}) {
         $fx_transaction = qq|
@@ -900,7 +935,7 @@ sub display_rows {
       if ($i < $form->{rowcount}) {
         if ($form->{transfer}) {
           $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
-          $x = ($checked) ? "x" : "";
+          my $x = ($checked) ? "x" : "";
           $fx_transaction = qq|
       <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
     |;
@@ -958,15 +993,19 @@ sub display_rows {
 
   $form->hide_form(qw(rowcount selectaccno));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub form_header {
   my ($init) = @_;
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my @old_project_ids = ();
   map({ push(@old_project_ids, $form->{"project_id_$_"})
@@ -981,14 +1020,14 @@ sub form_header {
 
   GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
 
-  $title         = $form->{title};
+  my $title      = $form->{title};
   $form->{title} = $locale->text("$title General Ledger Transaction");
-  $readonly      = ($form->{id}) ? "readonly" : "";
+  my $readonly   = ($form->{id}) ? "readonly" : "";
 
-  $show_details_checked = "checked" if $form->{show_details};
+  my $show_details_checked = "checked" if $form->{show_details};
 
-  $ob_transaction_checked = "checked" if $form->{ob_transaction};
-  $cb_transaction_checked = "checked" if $form->{cb_transaction};
+  my $ob_transaction_checked = "checked" if $form->{ob_transaction};
+  my $cb_transaction_checked = "checked" if $form->{cb_transaction};
 
   # $locale->text('Add General Ledger Transaction')
   # $locale->text('Edit General Ledger Transaction')
@@ -1029,7 +1068,8 @@ sub form_header {
   $form->{selectdepartment} =~
     s/option>\Q$form->{department}\E/option selected>$form->{department}/;
 
-  if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
+  my $description;
+  if ((my $rows = $form->numtextrows($form->{description}, 50)) > 1) {
     $description =
       qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
   } else {
@@ -1037,12 +1077,13 @@ sub form_header {
       qq|<input name=description size=50 value="$form->{description}" $readonly>|;
   }
 
-  $taxincluded = ($form->{taxincluded}) ? "checked" : "";
+  my $taxincluded = ($form->{taxincluded}) ? "checked" : "";
 
   if ($init) {
     $taxincluded = "checked";
   }
 
+  my $department;
   $department = qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Department') . qq|</th>
@@ -1058,7 +1099,8 @@ sub form_header {
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2);
   if ($form->{jsscript}) {
 
     # with JavaScript Calendar
@@ -1231,14 +1273,19 @@ sub form_header {
 
 $jsscript
 |;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my $follow_ups_block;
   if ($form->{id}) {
@@ -1250,10 +1297,10 @@ sub form_footer {
     }
   }
 
-  ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
+  my ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
   $dec = length $dec;
-  $decimalplaces = ($dec > 2) ? $dec : 2;
-  $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+  my $decimalplaces = ($dec > 2) ? $dec : 2;
+  my $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
   map {
     $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, "&nbsp;")
@@ -1277,8 +1324,8 @@ $follow_ups_block
 <br>
 |;
 
-  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
-  $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
+  my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+  my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
   if ($form->{id}) {
 
@@ -1322,12 +1369,15 @@ $follow_ups_block
 </body>
 </html>
 ";
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->header;
 
@@ -1341,7 +1391,7 @@ sub delete {
 
   delete $form->{header};
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
   }
@@ -1357,12 +1407,17 @@ sub delete {
     . $locale->text('Yes') . qq|">
 </form>
 |;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   if (GL->delete_transaction(\%myconfig, \%$form)){
     # saving the history
       if(!exists $form->{addition} && $form->{id} ne "") {
@@ -1374,20 +1429,24 @@ sub yes {
     $form->redirect($locale->text('Transaction deleted!'))
   }
   $form->error($locale->text('Cannot delete transaction!'));
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub post_transaction {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # check if there is something in reference and date
   $form->isblank("reference",   $locale->text('Reference missing!'));
   $form->isblank("transdate",   $locale->text('Transaction Date missing!'));
   $form->isblank("description", $locale->text('Description missing!'));
 
-  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
-  $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
+  my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+  my $closedto  = $form->datetonum($form->{closedto},  \%myconfig);
 
   my @a           = ();
   my $count       = 0;
@@ -1395,8 +1454,7 @@ sub post_transaction {
   my $credittax   = 0;
   my $debitcount  = 0;
   my $creditcount = 0;
-  $creditlock = 0;
-  $debitlock  = 0;
+  my $debitcredit;
 
   my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
 
@@ -1440,15 +1498,15 @@ sub post_transaction {
     if (!$debitcredit && $debittax) {
       $form->{"taxchart_$i"} = "0--0.00";
     }
-    $amount = ($form->{"debit_$i"} == 0)
+    my $amount = ($form->{"debit_$i"} == 0)
             ? $form->{"credit_$i"}
             : $form->{"debit_$i"};
-    $j = $#a;
+    my $j = $#a;
     if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
       $form->{"taxchart_$i"} = "0--0.00";
       $form->{"tax_$i"}      = 0;
     }
-    ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
+    my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
     if ($taxkey > 1) {
       if ($debitcredit) {
         $debittax = 1;
@@ -1473,18 +1531,19 @@ sub post_transaction {
     $count++;
   }
 
-  for $i (1 .. $count) {
-    $j = $i - 1;
+  for my $i (1 .. $count) {
+    my $j = $i - 1;
     for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
   }
 
-  for $i ($count + 1 .. $form->{rowcount}) {
+  for my $i ($count + 1 .. $form->{rowcount}) {
     for (@flds) { delete $form->{"${_}_$i"} }
   }
 
-  for $i (1 .. $form->{rowcount}) {
-    $dr  = $form->{"debit_$i"};
-    $cr  = $form->{"credit_$i"};
+  my ($debit, $credit, $taxtotal);
+  for my $i (1 .. $form->{rowcount}) {
+    my $dr  = $form->{"debit_$i"};
+    my $cr  = $form->{"credit_$i"};
     $tax = $form->{"tax_$i"};
     if ($dr && $cr) {
       $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
@@ -1507,8 +1566,9 @@ sub post_transaction {
     $form->error($locale->text('Empty transaction!'));
   }
 
-  if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
+  if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
     $errno *= -1;
+    my @err;
     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
     $err[2] = $locale->text('Debit and credit out of balance!');
     $err[3] = $locale->text('Cannot post a transaction without a value!');
@@ -1525,13 +1585,16 @@ sub post_transaction {
   }
   # /saving the history
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title}  = $locale->text("$form->{title} General Ledger Transaction");
   $form->{storno} = 0;
@@ -1543,24 +1606,30 @@ sub post {
   $form->{callback} = build_std_url("action=add", "show_details");
   $form->redirect($form->{callback});
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
 
   $form->{id} = 0;
   &add;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub storno {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # don't cancel cancelled transactions
   if (IS->has_storno(\%myconfig, $form, 'gl')) {
@@ -1580,9 +1649,11 @@ sub storno {
 
   $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub continue {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }
+
+1;
index 52d5c8b..3042403 100644 (file)
@@ -42,7 +42,7 @@ use SL::ReportGenerator;
 
 #use SL::PE;
 
-use strict;
+use strict;
 #use warnings;
 
 # global imports
index 71f3c01..54a9211 100644 (file)
@@ -1,10 +1,14 @@
 use SL::InstallationCheck;
 
+use strict;
+
 sub verify_installation {
   my $script = $0;
   $script =~ s|.*/||;
 
-  return unless ($form{"action"} && ($script eq "login.pl"));
+  my $form     = $main::form;
+
+  return unless ($form->{"action"} && ($script eq "login.pl"));
 
   SL::InstallationCheck::check_for_conditional_dependencies();
 
@@ -12,7 +16,7 @@ sub verify_installation {
   return if (scalar(@missing_modules) == 0);
 
   use SL::Locale;
-  my $locale = new Locale($language, "installationcheck");
+  my $locale = new Locale($main::language, "installationcheck");
 
   print(qq|content-type: text/html
 
index d947bae..b4290fe 100644 (file)
@@ -43,12 +43,14 @@ use SL::IC;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 # any custom scripts for this one
 if (-f "bin/mozilla/custom_invoice_io.pl") {
   eval { require "bin/mozilla/custom_ivvoice_io.pl"; };
 }
-if (-f "bin/mozilla/$form->{login}_invoice_io.pl") {
-  eval { require "bin/mozilla/$form->{login}_invoice_io.pl"; };
+if (-f "bin/mozilla/$main::form->{login}_invoice_io.pl") {
+  eval { require "bin/mozilla/$main::form->{login}_invoice_io.pl"; };
 }
 
 1;
@@ -91,7 +93,7 @@ use Data::Dumper;
 # neue Optik im Rechnungsformular      #
 ########################################
 #sub display_row {
-#  $lxdebug->enter_sub();
+#  $main::lxdebug->enter_sub();
 #  my $numrows = shift;
 #
 #  my $is_sales =
@@ -400,7 +402,7 @@ use Data::Dumper;
 #        # for last row
 #        $column_data{sellprice_pg} = qq|<td align="right">&nbsp;</td>|;
 #        }
-#        
+#
 #      $column_data{sellprice} =
 #      qq|<td><input name="sellprice_$i" size="10" onBlur=\"check_right_number_format(this)\" value="|
 #        . $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
@@ -546,25 +548,30 @@ use Data::Dumper;
 #    $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
 #  }
 #
-#  $lxdebug->leave_sub();
+#  $main::lxdebug->leave_sub();
 #}
 
 sub set_pricegroup {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my $rowcount = shift;
-  for $j (1 .. $rowcount) {
-    my $pricegroup_old = $form->{"pricegroup_old_$i"};
+  for my $j (1 .. $rowcount) {
+    my $pricegroup_old = $form->{"pricegroup_old_$j"};
     if ($form->{PRICES}{$j}) {
-      $len    = 0;
-      $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
-      $price  = 0;
-      foreach $item (@{ $form->{PRICES}{$j} }) {
+      my $len    = 0;
+      my $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
+      my $price  = 0;
+      foreach my $item (@{ $form->{PRICES}{$j} }) {
 
         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
         #$price = $form->format_amount($myconfig, $item->{price}, 2);
-        $price         = $item->{price};
-        $pricegroup_id = $item->{pricegroup_id};
-        $pricegroup    = $item->{pricegroup};
+        my $price         = $item->{price};
+        my $pricegroup_id = $item->{pricegroup_id};
+        my $pricegroup    = $item->{pricegroup};
 
         # build drop down list for pricegroups
         $prices .=
@@ -590,13 +597,16 @@ sub set_pricegroup {
       $form->{"prices_$j"} = $prices;
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | '.
                 'purchase_delivery_order_edit | sales_delivery_order_edit');
 
@@ -614,7 +624,7 @@ sub display_form {
     exit;
   }
 
-  Common::webdav_folder($form) if ($webdav);
+  Common::webdav_folder($form) if ($main::webdav);
 
   #   if (   $form->{print_and_post}
   #       && $form->{second_run}
@@ -651,48 +661,52 @@ sub display_form {
   #   }
   &form_header;
 
-  $numrows    = ++$form->{rowcount};
-  $subroutine = "display_row";
+  {
+    no strict 'refs';
 
-  if ($form->{item} eq 'part') {
+    my $numrows    = ++$form->{rowcount};
+    my $subroutine = "display_row";
 
-    #set preisgruppenanzahl
-    $numrows    = $form->{price_rows};
-    $subroutine = "price_row";
+    if ($form->{item} eq 'part') {
 
-    &{$subroutine}($numrows);
+      #set preisgruppenanzahl
+      $numrows    = $form->{price_rows};
+      $subroutine = "price_row";
 
-    $numrows    = ++$form->{makemodel_rows};
-    $subroutine = "makemodel_row";
-  }
-  if ($form->{item} eq 'assembly') {
-    $numrows    = $form->{price_rows};
-    $subroutine = "price_row";
+      &{$subroutine}($numrows);
 
-    &{$subroutine}($numrows);
+      $numrows    = ++$form->{makemodel_rows};
+      $subroutine = "makemodel_row";
+    }
+    if ($form->{item} eq 'assembly') {
+      $numrows    = $form->{price_rows};
+      $subroutine = "price_row";
 
-    $numrows    = ++$form->{makemodel_rows};
-    $subroutine = "makemodel_row";
+      &{$subroutine}($numrows);
 
-    # create makemodel rows
-    &{$subroutine}($numrows);
+      $numrows    = ++$form->{makemodel_rows};
+      $subroutine = "makemodel_row";
 
-    $numrows    = ++$form->{assembly_rows};
-    $subroutine = "assembly_row";
-  }
-  if ($form->{item} eq 'service') {
-    $numrows    = $form->{price_rows};
-    $subroutine = "price_row";
+      # create makemodel rows
+      &{$subroutine}($numrows);
 
-    &{$subroutine}($numrows);
+      $numrows    = ++$form->{assembly_rows};
+      $subroutine = "assembly_row";
+    }
+    if ($form->{item} eq 'service') {
+      $numrows    = $form->{price_rows};
+      $subroutine = "price_row";
 
-    $numrows = 0;
-  }
+      &{$subroutine}($numrows);
 
-  # create rows
-  &{$subroutine}($numrows) if $numrows;
+      $numrows = 0;
+    }
+
+    # create rows
+    &{$subroutine}($numrows) if $numrows;
+  }
 
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index 150f13a..b796a7b 100644 (file)
@@ -48,6 +48,8 @@ use SL::IO;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 # any custom scripts for this one
 if (-f "bin/mozilla/custom_io.pl") {
   eval { require "bin/mozilla/custom_io.pl"; };
@@ -103,10 +105,15 @@ sub _check_io_auth {
 # neue Optik im Rechnungsformular      #
 ########################################
 sub display_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   _check_io_auth();
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
   my $numrows = shift;
 
   my ($readonly, $stock_in_out, $stock_in_out_title);
@@ -169,12 +176,12 @@ sub display_row {
 
   # translations, unused commented out
 #  $runningnumber = $locale->text('No.');
-  $deliverydate  = $locale->text('Delivery Date');
-  $serialnumber  = $locale->text('Serial No.');
-  $projectnumber = $locale->text('Project');
+#  my $deliverydate  = $locale->text('Delivery Date');
+  my $serialnumber  = $locale->text('Serial No.');
+  my $projectnumber = $locale->text('Project');
 #  $partsgroup    = $locale->text('Group');
-  $reqdate       = $locale->text('Reqdate');
-  $deliverydate  = $locale->text('Required by');
+  my $reqdate       = $locale->text('Reqdate');
+  my $deliverydate  = $locale->text('Required by');
 
   # special alignings
   my %align  = map { $_ => 'right' } qw(qty ship right sellprice_pg discount linetotal stock_in_out);
@@ -196,7 +203,9 @@ sub display_row {
   _update_custom_variables();
 
   # rows
-  for $i (1 .. $numrows) {
+
+  my @ROWS;
+  for my $i (1 .. $numrows) {
     my %column_data = ();
 
     # undo formatting
@@ -237,15 +246,16 @@ sub display_row {
 # / unit ending
 
     $form->{"sellprice_$i"} =~ /\.(\d+)/;
-    $decimalplaces = max 2, length $1;
+    my $decimalplaces = max 2, length $1;
 
-    $price_factor   = $price_factors{$form->{"price_factor_id_$i"}} || 1;
-    $discount       = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} *        $form->{"discount_$i"}  / 100 / $price_factor, 2);
-    $linetotal      = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
+    my $price_factor   = $price_factors{$form->{"price_factor_id_$i"}} || 1;
+    my $discount       = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} *        $form->{"discount_$i"}  / 100 / $price_factor, 2);
+    my $linetotal      = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * (100 - $form->{"discount_$i"}) / 100 / $price_factor, 2);
+    my $rows            = $form->numtextrows($form->{"description_$i"}, 30, 6);
 
     $column_data{runningnumber} = $cgi->textfield(-name => "runningnumber_$i", -size => 5,  -value => $i);    # HuT
     $column_data{partnumber}    = $cgi->textfield(-name => "partnumber_$i",    -size => 12, -value => $form->{"partnumber_$i"});
-    $column_data{description} = ((($rows = $form->numtextrows($form->{"description_$i"}, 30, 6)) > 1) # if description is too large, use a textbox instead
+    $column_data{description} = (($rows > 1) # if description is too large, use a textbox instead
                                 ? $cgi->textarea( -name => "description_$i", -default => $form->{"description_$i"}, -rows => $rows, -columns => 30)
                                 : $cgi->textfield(-name => "description_$i",   -size => 30, -value => $form->{"description_$i"}))
                                 . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
@@ -385,43 +395,53 @@ sub display_row {
     $form->{marge_percent} = ($form->{sellprice_total} - $form->{lastcost_total}) / $form->{sellprice_total} * 100;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 ##################################################
 # build html-code for pricegroups in variable $form->{prices_$j}
 
 sub set_pricegroup {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   _check_io_auth();
 
   my $rowcount = shift;
-  for $j (1 .. $rowcount) {
+  for my $j (1 .. $rowcount) {
     next unless $form->{PRICES}{$j};
     # build drop down list for pricegroups
     my $option_tmpl = qq|<option value="%s--%s" %s>%s</option>|;
     $form->{"prices_$j"}  = join '', map { sprintf $option_tmpl, @$_{qw(price pricegroup_id selected pricegroup)} }
                                          (+{ pricegroup => $locale->text("none (pricegroup)") }, @{ $form->{PRICES}{$j} });
 
-    foreach $item (@{ $form->{PRICES}{$j} }) {
+    foreach my $item (@{ $form->{PRICES}{$j} }) {
       # set new selectedpricegroup_id and prices for "Preis"
       $form->{"pricegroup_old_$j"} = $item->{pricegroup_id}   if $item->{selected} &&  $item->{pricegroup_id};
       $form->{"sellprice_$j"}      = $item->{price}           if $item->{selected} &&  $item->{pricegroup_id};
       $form->{"price_new_$j"}      = $form->{"sellprice_$j"}  if $item->{selected} || !$item->{pricegroup_id};
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub select_item {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
 # diese variable kommt schon in der methode display_row vor, kann man die besser wiederverwenden? @mb fragen.  ich check das jetzt erstmal so ein
   my $is_purchase        = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl');
   _check_io_auth();
 
-  @column_index = qw(ndx partnumber description rop onhand unit sellprice);
-
+  my @column_index = qw(ndx partnumber description rop onhand unit sellprice);
+  my %column_data;
   $column_data{ndx}        = qq|<th>&nbsp;</th>|;
   $column_data{partnumber} =
     qq|<th class="listheading">| . $locale->text('Number') . qq|</th>|;
@@ -440,8 +460,8 @@ sub select_item {
   # list items with radio button on a form
   $form->header;
 
-  $title   = $locale->text('Select from one of the items below');
-  $colspan = $#column_index + 1;
+  my $title   = $locale->text('Select from one of the items below');
+  my $colspan = $#column_index + 1;
 
   print qq|
   <body>
@@ -463,17 +483,18 @@ sub select_item {
     qw(bin listprice inventory_accno income_accno expense_accno unit weight
        assembly taxaccounts partsgroup formel longdescription not_discountable
        part_payment_id partnotes id lastcost price_factor_id price_factor);
-  push @new_fields, "lizenzen" if ($lizenzen);
+  push @new_fields, "lizenzen" if ($main::lizenzen);
   push @new_fields, grep { m/^ic_cvar_/ } keys %{ $form->{item_list}->[0] };
 
   my $i = 0;
-  foreach $ref (@{ $form->{item_list} }) {
-    $checked = ($i++) ? "" : "checked";
+  my $j;
+  foreach my $ref (@{ $form->{item_list} }) {
+    my $checked = ($i++) ? "" : "checked";
 
-    if ($lizenzen) {
+    if ($main::lizenzen) {
       if ($ref->{inventory_accno} > 0) {
         $ref->{"lizenzen"} = qq|<option></option>|;
-        foreach $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
+        foreach my $item (@{ $form->{LIZENZEN}{ $ref->{"id"} } }) {
           $ref->{"lizenzen"} .=
             qq|<option value=\"$item->{"id"}\">$item->{"licensenumber"}</option>|;
         }
@@ -535,7 +556,7 @@ sub select_item {
   map { delete $form->{$_} } qw(action item_list header);
 
   # save all other form variables
-  foreach $key (keys %${form}) {
+  foreach my $key (keys %${form}) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input name="$key" type="hidden" value="$form->{$key}">\n|;
@@ -553,27 +574,30 @@ sub select_item {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub item_selected {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
   # replace the last row with the checked row
-  $i = $form->{rowcount};
+  my $i = $form->{rowcount};
   $i = $form->{assembly_rows} if ($form->{item} eq 'assembly');
 
   # index for new item
-  $j = $form->{ndx};
+  my $j = $form->{ndx};
 
   #sk
   #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
   #$form->{"sellprice_$i"} = $form->{"sellprice_$i"};
 
   # if there was a price entered, override it
-  $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+  my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
   my @new_fields =
     qw(id partnumber description sellprice listprice inventory_accno
@@ -592,13 +616,13 @@ sub item_selected {
     $form->{payment_id} = $form->{"part_payment_id_$i"};
   }
 
-  if ($lizenzen) {
+  if ($main::lizenzen) {
     map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } qw(lizenzen);
   }
 
-  ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+  my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
   $dec           = length $dec;
-  $decimalplaces = ($dec > 2) ? $dec : 2;
+  my $decimalplaces = ($dec > 2) ? $dec : 2;
 
   if ($sellprice) {
     $form->{"sellprice_$i"} = $sellprice;
@@ -622,7 +646,7 @@ sub item_selected {
     $form->{"discount_$i"} = 0;
   }
 
-  $amount =
+  my $amount =
     $form->{"sellprice_$i"} * (1 - $form->{"discount_$i"} / 100) *
     $form->{"qty_$i"};
   map { $form->{"${_}_base"} += $amount }
@@ -656,11 +680,14 @@ sub item_selected {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub new_item {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -673,6 +700,7 @@ sub new_item {
   # save all form variables except action in a previousform variable
   my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
 
+  my @HIDDENS;
   push @HIDDENS,      { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{$_} },                       qw(rowcount vc);
   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit);
@@ -683,11 +711,14 @@ sub new_item {
   $form->header();
   print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } );
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -759,7 +790,7 @@ sub check_form {
 
           map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
           $count++;
-          if ($lizenzen) {
+          if ($main::lizenzen) {
             if ($form->{"licensenumber_$i"} == -1) {
               &new_license($i);
               exit;
@@ -793,11 +824,14 @@ sub check_form {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoicetotal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -826,18 +860,21 @@ sub invoicetotal {
     if !$form->{taxincluded};
 
   $form->{oldtotalpaid} = 0;
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     $form->{oldtotalpaid} += $form->{"paid_$i"};
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   # return total
   return ($form->{oldinvtotal} - $form->{oldtotalpaid});
 }
 
 sub validate_items {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
@@ -847,16 +884,20 @@ sub validate_items {
     exit;
   }
 
-  for $i (1 .. $form->{rowcount} - 1) {
+  for my $i (1 .. $form->{rowcount} - 1) {
     $form->isblank("partnumber_$i",
                    $locale->text('Number missing in Row') . " $i");
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
@@ -869,6 +910,7 @@ sub order {
   $form->{old_salesman_id} = $form->{salesman_id};
 
   map { delete $form->{$_} } qw(id printed emailed queued);
+  my $buysell;
   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'request_quotation') {
     $form->{title} = $locale->text('Add Purchase Order');
     $form->{vc}    = 'vendor';
@@ -893,11 +935,11 @@ sub order {
   my $script = $form->{"script"};
   $script =~ s|.*/||;
   $script =~ s|.pl$||;
-  $locale = new Locale($language, $script);
+  $locale = new Locale($main::language, $script);
 
   map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
 
-  $currency = $form->{currency};
+  my $currency = $form->{currency};
 
   &order_links;
 
@@ -905,7 +947,7 @@ sub order {
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
   $form->{exchangerate} = $form->{forex} || '';
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"})
             if ($form->{"${_}_${i}"}) }
         qw(ship qty sellprice listprice basefactor discount));
@@ -914,11 +956,15 @@ sub order {
   &prepare_order;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub quotation {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
@@ -927,6 +973,7 @@ sub quotation {
   }
   map { delete $form->{$_} } qw(id printed emailed queued);
 
+  my $buysell;
   if ($form->{script} eq 'ir.pl' || $form->{type} eq 'purchase_order') {
     $form->{title} = $locale->text('Add Request for Quotation');
     $form->{vc}    = 'vendor';
@@ -952,7 +999,7 @@ sub quotation {
 
   map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
 
-  $currency = $form->{currency};
+  my $currency = $form->{currency};
 
   &order_links;
 
@@ -960,7 +1007,7 @@ sub quotation {
   $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, $buysell);
   $form->{exchangerate} = $form->{forex} || '';
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
                                                      $form->{"${_}_${i}"})
             if ($form->{"${_}_${i}"}) }
@@ -970,7 +1017,7 @@ sub quotation {
   &prepare_order;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub request_for_quotation {
@@ -978,7 +1025,11 @@ sub request_for_quotation {
 }
 
 sub edit_e_mail {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
@@ -994,7 +1045,7 @@ sub edit_e_mail {
     $form->{"email"} = $form->{"cp_email"};
   }
 
-  $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
+  my $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
 
   $form->{oldmedia} = $form->{media};
   $form->{media}    = "email";
@@ -1018,11 +1069,14 @@ sub edit_e_mail {
                                      HIDDEN        => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ],
                                      SHOW_BCC      => $myconfig{role} eq 'admin' });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub send_email {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -1036,7 +1090,7 @@ sub send_email {
   $form->{callback} = $callback;
   $form->redirect();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # generate the printing options displayed at the bottom of oe and is forms.
@@ -1049,7 +1103,11 @@ sub send_email {
 #
 # the inline options is untested, but intended to be used later in metatemplating
 sub print_options {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
@@ -1057,7 +1115,7 @@ sub print_options {
 
   # names 3 parameters and returns a hashref, for use in templates
   sub opthash { +{ value => shift, selected => shift, oname => shift } }
-  (@FORMNAME, @FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
+  my (@FORMNAME, @LANGUAGE_ID, @FORMAT, @SENDMODE, @MEDIA, @PRINTER_ID, @SELECTS) = ();
 
   # note: "||"-selection is only correct for values where "0" is _not_ a correct entry
   $form->{sendmode}   = "attachment";
@@ -1107,23 +1165,24 @@ sub print_options {
 
   push @MEDIA, grep $_,
       opthash("screen",              $form->{OP}{screen},              $locale->text('Screen')),
-    (scalar @{ $form->{printers} } && $latex_templates) ?
+    (scalar @{ $form->{printers} } && $main::latex_templates) ?
       opthash("printer",             $form->{OP}{printer},             $locale->text('Printer')) : undef,
-    ($latex_templates && !$options{no_queue}) ?
+    ($main::latex_templates && !$options{no_queue}) ?
       opthash("queue",               $form->{OP}{queue},               $locale->text('Queue')) : undef
         if ($form->{media} ne 'email');
 
   push @FORMAT, grep $_,
-    ($opendocument_templates && $openofficeorg_writer_bin && $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)
+    ($main::opendocument_templates &&     $main::openofficeorg_writer_bin  &&     $main::xvfb_bin
+                                   && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)
      && !$options{no_opendocument_pdf}) ?
       opthash("opendocument_pdf",    $form->{DF}{"opendocument_pdf"},  $locale->text("PDF (OpenDocument/OASIS)")) : undef,
-    ($latex_templates) ?
+    ($main::latex_templates) ?
       opthash("pdf",                 $form->{DF}{pdf},                 $locale->text('PDF')) : undef,
-    ($latex_templates && !$options{no_postscript}) ?
+    ($main::latex_templates && !$options{no_postscript}) ?
       opthash("postscript",          $form->{DF}{postscript},          $locale->text('Postscript')) : undef,
     (!$options{no_html}) ?
       opthash("html", $form->{DF}{html}, "HTML") : undef,
-    ($opendocument_templates && !$options{no_opendocument}) ?
+    ($main::opendocument_templates && !$options{no_opendocument}) ?
       opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef;
 
   push @LANGUAGE_ID,
@@ -1134,14 +1193,24 @@ sub print_options {
     map { opthash($_->{id}, ($_->{id} eq $form->{printer_id} ? 'selected' : ''), $_->{printer_description}) } +{}, @{ $form->{printers} }
       if ((ref $form->{printers} eq 'ARRAY') && scalar @{ $form->{printers } });
 
-  @SELECTS = map { sname => lc $_, DATA => \@$_, show => !$options{"hide_" . lc($_)} && scalar @$_ }, qw(FORMNAME LANGUAGE_ID FORMAT SENDMODE MEDIA PRINTER_ID);
+  @SELECTS = map {
+    sname => $_->[1],
+    DATA  => $_->[0],
+    show  => !$options{"hide_" . $_->[1]} && scalar @{ $_->[0] }
+  },
+  [ \@FORMNAME,    'formname',    ],
+  [ \@LANGUAGE_ID, 'language_id', ],
+  [ \@FORMAT,      'format',      ],
+  [ \@SENDMODE,    'sendmode',    ],
+  [ \@MEDIA,       'media',       ],
+  [ \@PRINTER_ID,  'printer_id',  ];
 
   my %dont_display_groupitems = (
     'dunning' => 1,
     );
 
-  %template_vars = (
-    display_copies       => scalar @{ $form->{printers} } && $latex_templates && $form->{media} ne 'email',
+  my %template_vars = (
+    display_copies       => scalar @{ $form->{printers} } && $main::latex_templates && $form->{media} ne 'email',
     display_remove_draft => (!$form->{id} && $form->{draft_id}),
     display_groupitems   => !$dont_display_groupitems{$form->{type}},
     groupitems_checked   => $form->{groupitems} ? "checked" : '',
@@ -1151,27 +1220,31 @@ sub print_options {
   my $print_options = $form->parse_html_template("generic/print_options", { SELECTS  => \@SELECTS, %template_vars } );
 
   if ($options{inline}) {
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return $print_options;
   }
 
   print $print_options;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
   if ($form->{print_nextsub}) {
     call_sub($form->{print_nextsub});
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
   # if this goes to the printer pass through
+  my $old_form;
   if ($form->{media} eq 'printer' || $form->{media} eq 'queue') {
     $form->error($locale->text('Select postscript or PDF!'))
       if ($form->{format} !~ /(postscript|pdf)/);
@@ -1194,21 +1267,26 @@ sub print {
 
   &print_form($old_form);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   _check_io_auth();
 
   my ($old_form) = @_;
 
-  $inv       = "inv";
-  $due       = "due";
-  $numberfld = "invnumber";
+  my $inv       = "inv";
+  my $due       = "due";
+  my $numberfld = "invnumber";
+  my $order;
 
-  $display_form =
+  my $display_form =
     ($form->{display_form}) ? $form->{display_form} : "display_form";
 
   # $form->{"notes"} will be overridden by the customer's/vendor's "notes" field. So save it here.
@@ -1361,10 +1439,10 @@ sub print_form {
   my ($saved_email, $saved_cc, $saved_bcc) =
     ($form->{"email"}, $form->{"cc"}, $form->{"bcc"});
 
-  $language_saved = $form->{language_id};
-  $payment_id_saved = $form->{payment_id};
-  $salesman_id_saved = $form->{salesman_id};
-  $cp_id_saved = $form->{cp_id};
+  my $language_saved = $form->{language_id};
+  my $payment_id_saved = $form->{payment_id};
+  my $salesman_id_saved = $form->{salesman_id};
+  my $cp_id_saved = $form->{cp_id};
 
   call_sub("$form->{vc}_details") if ($form->{vc});
 
@@ -1410,12 +1488,12 @@ sub print_form {
     $form->get_shipto(\%myconfig);
   }
 
-  @a = qw(name street zipcode city country contact);
+  my @a = qw(name street zipcode city country contact);
 
-  $shipto = 1;
+  my $shipto = 1;
 
   # if there is no shipto fill it in from billto
-  foreach $item (@a) {
+  foreach my $item (@a) {
     if ($form->{"shipto$item"}) {
       $shipto = 0;
       last;
@@ -1527,7 +1605,7 @@ sub print_form {
     $form->{printed} .= " $form->{formname}";
     $form->{printed} =~ s/^ //;
   }
-  $printed = $form->{printed};
+  my $printed = $form->{printed};
 
   if ($form->{media} eq 'email') {
     $form->{subject} = qq|$form->{label} $form->{"${inv}number"}|
@@ -1536,14 +1614,15 @@ sub print_form {
     $form->{emailed} .= " $form->{formname}";
     $form->{emailed} =~ s/^ //;
   }
-  $emailed = $form->{emailed};
+  my $emailed = $form->{emailed};
 
   if ($form->{media} eq 'queue') {
-    %queued = map { s|.*/|| } split / /, $form->{queued};
+    my %queued = map { s|.*/|| } split / /, $form->{queued};
 
+    my $filename;
     if ($filename = $queued{ $form->{formname} }) {
       $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
-      unlink "$spool/$filename";
+      unlink "$main::spool/$filename";
       $filename =~ s/\..*$//g;
     } else {
       $filename = time;
@@ -1551,14 +1630,14 @@ sub print_form {
     }
 
     $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
-    $form->{OUT} = ">$spool/$filename";
+    $form->{OUT} = ">$main::spool/$filename";
 
     # add type
     $form->{queued} .= " $form->{formname} $filename";
 
     $form->{queued} =~ s/^ //;
   }
-  $queued = $form->{queued};
+  my $queued = $form->{queued};
 
 # saving the history
   if(!exists $form->{addition}) {
@@ -1579,14 +1658,14 @@ sub print_form {
   }
   # /saving the history
 
-  $form->parse_template(\%myconfig, $userspath);
+  $form->parse_template(\%myconfig, $main::userspath);
 
   $form->{callback} = "";
 
   if ($form->{media} eq 'email') {
     $form->{message} = $locale->text('sent') unless $form->{message};
   }
-  $message = $form->{message};
+  my $message = $form->{message};
 
   # if we got back here restore the previous form
   if ($form->{media} =~ /(printer|email|queue)/) {
@@ -1594,7 +1673,7 @@ sub print_form {
     $form->update_status(\%myconfig)
       if ($form->{media} eq 'queue' && $form->{id});
 
-    return $lxdebug->leave_sub() if ($old_form eq "return");
+    return $main::lxdebug->leave_sub() if ($old_form eq "return");
 
     if ($old_form) {
 
@@ -1612,7 +1691,7 @@ sub print_form {
       map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
         qw(exchangerate creditlimit creditremaining);
 
-      for $i (1 .. $form->{paidaccounts}) {
+      for my $i (1 .. $form->{paidaccounts}) {
         map {
           $form->{"${_}_$i"} =
             $form->parse_amount(\%myconfig, $form->{"${_}_$i"})
@@ -1623,7 +1702,7 @@ sub print_form {
       exit;
     }
 
-    $msg =
+    my $msg =
       ($form->{media} eq 'printer')
       ? $locale->text('sent to printer')
       : $locale->text('emailed to') . " $form->{email}";
@@ -1634,27 +1713,35 @@ sub print_form {
    exit;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub customer_details {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   IS->customer_details(\%myconfig, \%$form, @_);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub vendor_details {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   IR->vendor_details(\%myconfig, \%$form, @_);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   _check_io_auth();
 
@@ -1663,11 +1750,16 @@ sub post_as_new {
 
   &post;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub ship_to {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   _check_io_auth();
 
@@ -1675,7 +1767,7 @@ sub ship_to {
     $form->{print_and_post} = 0;
   }
 
-  $title = $form->{title};
+  my $title = $form->{title};
   $form->{title} = $locale->text('Ship to');
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
@@ -1693,7 +1785,7 @@ sub ship_to {
   # get details for name
   call_sub("$form->{vc}_details", @addr_vars);
 
-  $number =
+  my $number =
     ($form->{vc} eq 'customer')
     ? $locale->text('Customer Number')
     : $locale->text('Vendor Number');
@@ -1704,7 +1796,7 @@ sub ship_to {
   # build up html code for prices_$i
   set_pricegroup($form->{rowcount});
 
-  $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
+  my $nextsub = ($form->{display_form}) ? $form->{display_form} : "display_form";
 
   $form->{rowcount}--;
 
@@ -1798,7 +1890,7 @@ sub ship_to {
   map({ delete $form->{$_} } (@shipto_vars, qw(header)));
   $form->{title} = $title;
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
@@ -1817,11 +1909,13 @@ sub ship_to {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub new_license {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   _check_io_auth();
 
@@ -1834,12 +1928,13 @@ sub new_license {
 
   # delete action
   delete $form->{action};
-  $customer = $form->{customer};
+  my $customer = $form->{customer};
   map { $form->{"old_$_"} = $form->{"${_}_$row"} } qw(partnumber description);
 
   # save all other form variables in a previousform variable
   $form->{row} = $row;
-  foreach $key (keys %$form) {
+  my $previousform;
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
     # escape ampersands
@@ -1851,6 +1946,8 @@ sub new_license {
 
   $form->{script} = "licenses.pl";
 
+  our $name;
+
   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
   map { $form->{$_} = $form->escape($form->{$_}, 1) }
     qw(partnumber description);
@@ -1858,11 +1955,14 @@ sub new_license {
     qq|$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&customer=$customer&partnumber=$form->{partnumber}&description=$form->{description}&previousform="$previousform"&initial=1|;
   $form->redirect;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub relink_accounts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -1879,11 +1979,14 @@ sub relink_accounts {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_duedate {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   _check_io_auth();
 
@@ -1892,11 +1995,13 @@ sub set_duedate {
 
   print $form->ajax_response_header() . $duedate;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _update_part_information {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my %part_information = IC->get_basic_part_info('id'        => [ grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}) ],
                                                  'vendor_id' => $form->{vendor_id});
@@ -1910,19 +2015,22 @@ sub _update_part_information {
     $form->{"partunit_${i}"} = $info->{unit};
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _update_ship {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   if (!$form->{ordnumber} || !$form->{id}) {
     map { $form->{"ship_$_"} = 0 } (1..$form->{rowcount});
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
-  AM->retrieve_all_units();
+  my $all_units = AM->retrieve_all_units();
 
   my %ship = DO->get_shipped_qty('type'  => ($form->{type} eq 'purchase_order') ? 'purchase' : 'sales',
                                  'oe_id' => $form->{id},);
@@ -1956,25 +2064,29 @@ sub _update_ship {
     $ship_entry->{qty}  = 0;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _update_custom_variables {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   $form->{CVAR_CONFIGS}       ||= { };
   $form->{CVAR_CONFIGS}->{IC}   = CVar->get_configs(module => 'IC');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub _render_custom_variables_inputs {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my %params = @_;
 
   if (!$form->{CVAR_CONFIGS}->{IC}) {
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -2004,5 +2116,5 @@ sub _render_custom_variables_inputs {
                              };
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index 440ee6e..d848abc 100644 (file)
@@ -43,16 +43,21 @@ require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
 require "bin/mozilla/drafts.pl";
 
+use strict;
+
 1;
 
 # end of main
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
-  return $lxdebug->leave_sub() if (load_draft_maybe());
+  return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
   $form->{title} = $locale->text('Add Vendor Invoice');
 
@@ -60,13 +65,16 @@ sub add {
   &prepare_invoice;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('vendor_invoice_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('vendor_invoice_edit');
 
   # show history button
   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
@@ -78,22 +86,25 @@ sub edit {
   &prepare_invoice;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoice_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   # create links
-  $form->{webdav}   = $webdav;
+  $form->{webdav}   = $main::webdav;
   $form->{jsscript} = 1;
 
   $form->create_links("AP", \%myconfig, "vendor");
 
   #quote all_vendor Bug 133
-  foreach $ref (@{ $form->{all_vendor} }) {
+  foreach my $ref (@{ $form->{all_vendor} }) {
     $ref->{name} = $form->quote($ref->{name});
   }
 
@@ -102,6 +113,8 @@ sub invoice_links {
       $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
     }
   }
+
+  my ($payment_id, $language_id, $taxzone_id);
   if ($form->{payment_id}) {
     $payment_id = $form->{payment_id};
   }
@@ -112,7 +125,7 @@ sub invoice_links {
     $taxzone_id = $form->{taxzone_id};
   }
 
-  $cp_id = $form->{cp_id};
+  my $cp_id = $form->{cp_id};
   IR->get_vendor(\%myconfig, \%$form);
   IR->retrieve_invoice(\%myconfig, \%$form);
   $form->{cp_id} = $cp_id;
@@ -127,6 +140,7 @@ sub invoice_links {
     $form->{taxzone_id} = $taxzone_id;
   }
 
+  my @curr = split(/:/, $form->{currencies}); #seems to be missing
   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
 
   $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
@@ -144,16 +158,18 @@ sub invoice_links {
 
   # forex
   $form->{forex} = $form->{exchangerate};
-  $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
+  my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
-  foreach $key (keys %{ $form->{AP_links} }) {
+  foreach my $key (keys %{ $form->{AP_links} }) {
 
-    foreach $ref (@{ $form->{AP_links}{$key} }) {
+    foreach my $ref (@{ $form->{AP_links}{$key} }) {
       $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
     }
 
+    next unless $form->{acc_trans}{$key};
+
     if ($key eq "AP_paid") {
-      for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
+      for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
         $form->{"AP_paid_$i"} =
           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
@@ -183,26 +199,29 @@ sub invoice_links {
     ($form->datetonum($form->{invdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub prepare_invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   if ($form->{id}) {
 
     map { $form->{$_} =~ s/\"/&quot;/g } qw(invnumber ordnumber quonumber);
 
     my $i = 0;
-    foreach $ref (@{ $form->{invoice_details} }) {
+    foreach my $ref (@{ $form->{invoice_details} }) {
       $i++;
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
 
-      ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+      my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
       $dec           = length $dec;
-      $decimalplaces = ($dec > 2) ? $dec : 2;
+      my $decimalplaces = ($dec > 2) ? $dec : 2;
 
       $form->{"sellprice_$i"} =
         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
@@ -218,18 +237,23 @@ sub prepare_invoice {
     }
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('vendor_invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
+  $main::auth->assert('vendor_invoice_edit');
 
   push @{ $form->{AJAX} }, CGI::Ajax->new('set_duedate_vendor' => "$form->{script}?action=set_duedate_vendor");
 
   # set option selected
-  foreach $item (qw(AP vendor currency department)) {
+  foreach my $item (qw(AP vendor currency department)) {
     $form->{"select$item"} =~ s/ selected//;
     $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
@@ -242,7 +266,7 @@ sub form_header {
   $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
   $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
-  $exchangerate = "";
+  my $exchangerate = "";
   if ($form->{currency} ne $form->{defaultcurrency}) {
     if ($form->{forex}) {
       $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
@@ -316,7 +340,6 @@ sub form_header {
 
   %labels = ();
   @values = ();
-  my $i = 0;
   foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
     push(@values, $item->{"id"});
     $labels{$item->{"id"}} = $item->{"name"};
@@ -331,7 +354,6 @@ sub form_header {
 
   %labels = ();
   @values = ();
-  my $i = 0;
   foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
     push(@values, $item->{name}.qq|--|.$item->{"id"});
     $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
@@ -357,6 +379,7 @@ sub form_header {
     $labels{$item->{"id"}} = $item->{"description"};
   }
 
+  my $taxzone;
   if (!$form->{"id"}) {
     $taxzone = qq|
     <tr>
@@ -376,7 +399,7 @@ sub form_header {
     </tr>|;
   }
 
-  $department = qq|
+  my $department = qq|
            <tr>
              <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
              <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
@@ -384,13 +407,13 @@ sub form_header {
              </td>
            </tr>\n| if $form->{selectdepartment};
 
-  $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+  my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
 
-  $button1 = qq|
+  my $button1 = qq|
      <td nowrap>
          <input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\"
                 onChange="if (this.value) set_duedate_vendor(['invdate__' + this.value, 'old_duedate__' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
@@ -398,7 +421,7 @@ sub form_header {
      </td>\n|;
 
 #, 'old_duedate__'' + document.getElementsByName('duedate')[0].value, 'vendor_id__' + document.getElementsByName('vendor_id')[0].value],['duedate'])">
-  $button2 = qq|
+  my $button2 = qq|
      <td width="13" nowrap>
           <input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}"  onBlur=\"check_right_date_format(this)\">
           <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|>
@@ -422,7 +445,7 @@ sub form_header {
   $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
 
   $form->header;
-  $onload  = qq|focus()|;
+  my $onload  = qq|focus()|;
   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   print qq|
@@ -509,26 +532,32 @@ sub form_header {
 
 $jsscript
 
-<input type=hidden name=webdav value=$webdav>
+<input type=hidden name=webdav value=$main::webdav>
 |;
 
-  foreach $item (split / /, $form->{taxaccounts}) {
+  foreach my $item (split / /, $form->{taxaccounts}) {
     print qq|
 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
 |;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   $form->{invtotal} = $form->{invsubtotal};
 
+  my ($rows, $introws);
   if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
     $rows = 2;
   }
@@ -536,14 +565,14 @@ sub form_footer {
     $introws = 2;
   }
   $rows = ($rows > $introws) ? $rows : $introws;
-  $notes =
+  my $notes =
     qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
-  $intnotes =
+  my $intnotes =
     qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
 
   $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
 
-  $taxincluded = "";
+  my $taxincluded = "";
   if ($form->{taxaccounts}) {
     $taxincluded = qq|
                <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
@@ -551,9 +580,10 @@ sub form_footer {
 |;
   }
 
+  my ($tax, $subtotal);
   if (!$form->{taxincluded}) {
 
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{invtotal} += $form->{"${item}_total"} =
           $form->round_amount(
@@ -585,7 +615,7 @@ sub form_footer {
   }
 
   if ($form->{taxincluded}) {
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{"${item}_total"} =
           $form->round_amount(
@@ -638,6 +668,7 @@ sub form_footer {
     }
   }
 
+  our $colspan;
   print qq|
   <tr>
     <td colspan=$colspan>
@@ -673,7 +704,8 @@ sub form_footer {
     </td>
   </tr>
 |;
-  if ($webdav) {
+  my $webdav_list;
+  if ($main::webdav) {
     $webdav_list = qq|
   <tr>
     <td><hr size=3 noshade></td>
@@ -685,7 +717,7 @@ sub form_footer {
       <td align=left width=30%><b>Dateiname</b></td>
       <td align=left width=70%><b>Webdavlink</b></td>
 |;
-    foreach $file (@{ $form->{WEBDAV} }) {
+    foreach my $file (@{ $form->{WEBDAV} }) {
       $webdav_list .= qq|
       <tr>
         <td align="left">$file->{name}</td>
@@ -709,12 +741,14 @@ sub form_footer {
        </tr>
 |;
 
+  my @column_index;
   if ($form->{currency} eq $form->{defaultcurrency}) {
     @column_index = qw(datepaid source memo paid AP_paid);
   } else {
     @column_index = qw(datepaid source memo paid exchangerate AP_paid);
   }
 
+  my %column_data;
   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
@@ -734,7 +768,7 @@ sub form_footer {
   my $totalpaid = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
 
     print qq|
        <tr>
@@ -754,7 +788,7 @@ sub form_footer {
     $form->{"exchangerate_$i"} =
       $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
 
-    $exchangerate = qq|&nbsp;|;
+    my $exchangerate = qq|&nbsp;|;
     if ($form->{currency} ne $form->{defaultcurrency}) {
       if ($form->{"forex_$i"}) {
         $exchangerate =
@@ -818,8 +852,8 @@ sub form_footer {
 <br>
 |;
 
-  $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
-  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+  my $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
+  my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
   print qq|<input class=submit type=submit name=action id=update_button value="|
     . $locale->text('Update') . qq|">
@@ -880,40 +914,46 @@ print qq|</form>
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub mark_as_paid {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   &mark_as_paid_common(\%myconfig,"ap");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
 
-  &check_name(vendor);
+  &check_name('vendor');
 
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     next unless $form->{"paid_$i"};
     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
     $form->{"forex_$i"}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
     $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
   }
 
-  $i            = $form->{rowcount};
-  $exchangerate = ($form->{exchangerate} * 1) || 1;
+  my $i            = $form->{rowcount};
+  my $exchangerate = ($form->{exchangerate} * 1) || 1;
 
   if (   ($form->{"partnumber_$i"} eq "")
       && ($form->{"description_$i"} eq "")
@@ -938,10 +978,10 @@ sub update {
       } else {
 
         # override sellprice if there is one entered
-        $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+        my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
        # ergaenzung fuer bug 736 Lieferanten-Rabatt auch in Einkaufsrechnungen vorbelegen jb
-        $form->{"discount_$i"} = $form->format_amount(\%myconfig, 
+        $form->{"discount_$i"} = $form->format_amount(\%myconfig,
                                                      $form->{vendor_discount} * 100 );
         map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g } qw(partnumber description unit);
         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
@@ -949,7 +989,8 @@ sub update {
         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
 
         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
-        $decimalplaces = max 2, length $1;
+        my $dec_qty       = length $1;
+        my $decimalplaces = max 2, $dec_qty;
 
         if ($sellprice) {
           $form->{"sellprice_$i"} = $sellprice;
@@ -958,7 +999,7 @@ sub update {
           $form->{"sellprice_$i"} /= $exchangerate;
         }
 
-        $amount                   = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+        my $amount                   = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
         $form->{creditremaining} -= $amount;
         $form->{"sellprice_$i"}   = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
         $form->{"qty_$i"}         = $form->format_amount(\%myconfig, $form->{"qty_$i"},       $dec_qty);
@@ -984,13 +1025,17 @@ sub update {
       }
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub storno {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   if ($form->{storno}) {
     $form->error($locale->text('Cannot storno storno invoice!'));
@@ -1024,14 +1069,17 @@ sub storno {
   $form->{rowcount}++;
   $form->{employee_id} = $employee_id;
   post();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub use_as_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('vendor_invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('vendor_invoice_edit');
 
   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
@@ -1039,18 +1087,22 @@ sub use_as_template {
   $form->{invdate} = $form->current_date(\%myconfig);
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->{"paid_$i"}) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -1058,10 +1110,8 @@ sub post_payment {
         if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
 
       if ($form->{currency} ne $form->{defaultcurrency}) {
-        $form->{"exchangerate_$i"} = $form->{exchangerate}
-          if ($invdate == $datepaid);
-        $form->isblank("exchangerate_$i",
-                       $locale->text('Exchangerate for payment missing!'));
+#        $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); # invdate isn't set here
+        $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
       }
     }
   }
@@ -1083,13 +1133,17 @@ sub post_payment {
 
   $form->error($locale->text('Cannot post payment!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
@@ -1101,15 +1155,16 @@ sub post {
   $form->{invnumber} =~ s/\s*$//g;
 
   # if the vendor changed get new values
-  if (&check_name(vendor)) {
+  if (&check_name('vendor')) {
     &update;
     exit;
   }
 
   &validate_items;
 
-  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
-  $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
+  my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+  my $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
+  my $i        = $form->{rowcount};
 
   $form->error($locale->text('Cannot post invoice for a closed period!'))
     if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
@@ -1119,7 +1174,7 @@ sub post {
 
   for $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -1159,13 +1214,16 @@ sub post {
   }
   $form->error($locale->text('Cannot post invoice!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('vendor_invoice_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('vendor_invoice_edit');
 
   $form->header;
   print qq|
@@ -1177,7 +1235,7 @@ sub delete {
   # delete action variable
   map { delete $form->{$_} } qw(action header);
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
@@ -1195,13 +1253,17 @@ sub delete {
 </form>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('vendor_invoice_edit');
+  $main::auth->assert('vendor_invoice_edit');
 
   if (IR->delete_invoice(\%myconfig, \%$form)) {
     # saving the history
@@ -1215,15 +1277,17 @@ sub yes {
   }
   $form->error($locale->text('Cannot delete invoice!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_duedate_vendor {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
                                                        'invdate'   => $form->{invdate},
                                                        'default'   => $form->{old_duedate});
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index 9bc225e..d67cd56 100644 (file)
@@ -42,16 +42,25 @@ require "bin/mozilla/invoice_io.pl";
 require "bin/mozilla/arap.pl";
 require "bin/mozilla/drafts.pl";
 
+use strict;
+
+my $edit;
+my $payment;
+my $print_post;
+
 1;
 
 # end of main
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  return $lxdebug->leave_sub() if (load_draft_maybe());
+  $main::auth->assert('invoice_edit');
+
+  return $main::lxdebug->leave_sub() if (load_draft_maybe());
 
   if ($form->{type} eq "credit_note") {
     $form->{title} = $locale->text('Add Credit Note');
@@ -67,25 +76,28 @@ sub add {
 
   $form->{callback} = "$form->{script}?action=add&type=$form->{type}" unless $form->{callback};
 
-  $form{jsscript} = "date";
+  $form->{jsscript} = "date";
 
   &invoice_links;
   &prepare_invoice;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
   #/show hhistory button
 
   $edit = 1;
+  my ($language_id, $printer_id);
   if ($form->{print_and_post}) {
     $form->{action}   = "print";
     $form->{resubmit} = 1;
@@ -101,19 +113,22 @@ sub edit {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoice_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('invoice_edit');
 
   $form->{vc} = 'customer';
 
   # create links
-  $form->{webdav}   = $webdav;
-  $form->{lizenzen} = $lizenzen;
+  $form->{webdav}   = $main::webdav;
+  $form->{lizenzen} = $main::lizenzen;
 
   $form->create_links("AR", \%myconfig, "customer");
 
@@ -124,27 +139,32 @@ sub invoice_links {
     }
   }
 
+  my $payment_id;
   if ($form->{payment_id}) {
     $payment_id = $form->{payment_id};
   }
+  my $language_id;
   if ($form->{language_id}) {
     $language_id = $form->{language_id};
   }
+  my $taxzone_id;
   if ($form->{taxzone_id}) {
     $taxzone_id = $form->{taxzone_id};
   }
+  my $id;
   if ($form->{id}) {
     $id = $form->{id};
   }
+  my $shipto_id;
   if ($form->{shipto_id}) {
     $shipto_id = $form->{shipto_id};
   }
 
-  $cp_id = $form->{cp_id};
+  my $cp_id = $form->{cp_id};
   IS->get_customer(\%myconfig, \%$form);
 
   #quote all_customer Bug 133
-  foreach $ref (@{ $form->{all_customer} }) {
+  foreach my $ref (@{ $form->{all_customer} }) {
     $ref->{name} = $form->quote($ref->{name});
   }
   if ($id) {
@@ -183,16 +203,17 @@ sub invoice_links {
 
   # forex
   $form->{forex} = $form->{exchangerate};
-  $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
+  my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
 
-  foreach $key (keys %{ $form->{AR_links} }) {
-    foreach $ref (@{ $form->{AR_links}{$key} }) {
+  foreach my $key (keys %{ $form->{AR_links} }) {
+    foreach my $ref (@{ $form->{AR_links}{$key} }) {
       $form->{"select$key"} .=
 "<option>$ref->{accno}--$ref->{description}</option>\n";
     }
 
     if ($key eq "AR_paid") {
-      for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
+      next unless $form->{acc_trans}{$key};
+      for my $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
         $form->{"AR_paid_$i"} =
           "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
 
@@ -222,13 +243,16 @@ sub invoice_links {
     ($form->datetonum($form->{invdate}, \%myconfig) <=
      $form->datetonum($form->{closedto}, \%myconfig));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub prepare_invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   if ($form->{type} eq "credit_note") {
     $form->{type}     = "credit_note";
@@ -246,15 +270,15 @@ sub prepare_invoice {
 
     my $i = 0;
 
-    foreach $ref (@{ $form->{invoice_details} }) {
+    foreach my $ref (@{ $form->{invoice_details} }) {
       $i++;
 
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
       $form->{"discount_$i"} =
         $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-      ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+      my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
       $dec           = length $dec;
-      $decimalplaces = ($dec > 2) ? $dec : 2;
+      my $decimalplaces = ($dec > 2) ? $dec : 2;
 
       $form->{"sellprice_$i"} =
         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
@@ -270,13 +294,18 @@ sub prepare_invoice {
 
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
   $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
@@ -294,7 +323,7 @@ sub form_header {
   $form->{radier}          = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
 
   $payment = qq|<option value=""></option>|;
-  foreach $item (@{ $form->{payment_terms} }) {
+  foreach my $item (@{ $form->{payment_terms} }) {
     if ($form->{payment_id} eq $item->{id}) {
       $payment .= qq|<option value="$item->{id}" selected>$item->{description}</option>|;
     } else {
@@ -427,7 +456,7 @@ sub form_header {
     $labels{$item->{id}} = $item->{name} ne "" ? $item->{name} : $item->{login};
   }
 
-  $salesman =
+  my $salesman =
     qq|<tr> <th align="right">| . $locale->text('Salesman') . qq|</th>
          <td>| . NTI($cgi->popup_menu('-name' => 'salesman_id', '-values' => \@values, '-labels' => \%labels,
                                       '-default' => $form->{salesman_id} ? $form->{salesman_id} : $form->{employee_id})) . qq|
@@ -441,6 +470,7 @@ sub form_header {
     $labels{$item->{"id"}} = $item->{"description"};
   }
 
+  my $taxzone;
   if (!$form->{"id"}) {
     $taxzone = qq|
     <tr>
@@ -462,18 +492,18 @@ sub form_header {
   }
 
   # set option selected
-  foreach $item (qw(AR customer currency department employee)) {
+  foreach my $item (qw(AR customer currency department employee)) {
     $form->{"select$item"} =~ s/ selected//;
     $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
   }
 
-  $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
+  my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
 
   $form->{exchangerate}    = $form->format_amount(\%myconfig, $form->{exchangerate});
   $form->{creditlimit}     = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
   $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
-  $exchangerate = "";
+  my $exchangerate = "";
   if ($form->{currency} ne $form->{defaultcurrency}) {
     if ($form->{forex}) {
       $exchangerate .= qq|<th align="right">| . $locale->text('Exchangerate') . qq|</th>
@@ -485,7 +515,7 @@ sub form_header {
   }
   $exchangerate .= qq|\n<input type="hidden" name="forex" value="$form->{forex}">\n|;
 
-  $department = qq|
+  my $department = qq|
               <tr>
                <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
                <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
@@ -494,8 +524,9 @@ sub form_header {
              </tr>
 | if $form->{selectdepartment};
 
-  $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
+  my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
+  my $business;
   if ($form->{business}) {
     $business = qq|
              <tr>
@@ -507,6 +538,7 @@ sub form_header {
 |;
   }
 
+  my $dunning;
   if ($form->{max_dunning_level}) {
     $dunning = qq|
       <tr>
@@ -525,7 +557,8 @@ sub form_header {
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ($button1, $button2, $button3);
   if ($form->{type} eq "credit_note") {
     $button1 = qq|
       <td nowrap><input name="invdate" id="invdate" size="11" title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
@@ -557,18 +590,18 @@ sub form_header {
     #write Trigger
     $jsscript =
       Form->write_trigger(\%myconfig,     "3",
-                          "invdate",      "BL", "trigger1", 
+                          "invdate",      "BL", "trigger1",
                           "duedate",      "BL", "trigger2",
                           "deliverydate", "BL", "trigger3");
   }
 
-  $credittext = $locale->text('Credit Limit exceeded!!!');
+  my $credittext = $locale->text('Credit Limit exceeded!!!');
 
   my $follow_up_vc         =  $form->{customer};
   $follow_up_vc            =~ s/--\d*\s*$//;
   my $follow_up_trans_info =  "$form->{invnumber} ($follow_up_vc)";
 
-  $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
+  my $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|
           : ($form->{resubmit})                                ? qq|document.invoice.submit()|
           : ($creditwarning)                                   ? qq|alert('$credittext')|
           :                                                      "focus()";
@@ -601,11 +634,11 @@ sub form_header {
   $form->hide_form(qw(id action type media format queued printed emailed title vc discount
                       creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
                       max_dunning_level dunning_amount
-                      shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax 
+                      shiptoname shiptostreet shiptozipcode shiptocity shiptocountry  shiptocontact shiptophone shiptofax
                       shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
                       convert_from_do_ids convert_from_oe_ids),
                       map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} );
-   
+
   print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
 
   print qq|
@@ -615,7 +648,7 @@ sub form_header {
 <input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
 <input type="hidden" name="follow_up_rowcount" value="1">
 
-<input type="hidden" name="lizenzen" value="$lizenzen">
+<input type="hidden" name="lizenzen" value="$main::lizenzen">
 
 <div class="listtop" width="100%">$form->{title}</div>
 
@@ -700,7 +733,7 @@ if ($form->{type} eq "credit_note") {
 print qq|     <tr>
                <th align="right" nowrap>| . $locale->text('Credit Note Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .        
+               $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
       qq|      </td>
              </tr>
              <tr>
@@ -711,7 +744,7 @@ print qq|     <tr>
 print qq|     <tr>
                <th align="right" nowrap>| . $locale->text('Invoice Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .        
+               $cgi->textfield("-name" => "invnumber", "-size" => 11, "-value" => $form->{invnumber}) .
       qq|      </td>
              </tr>
              <tr>
@@ -725,7 +758,7 @@ print qq|     <tr>
              <tr>
                <th align="right" nowrap>| . $locale->text('Delivery Order Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .  
+               $cgi->textfield("-name" => "donumber", "-size" => 11, "-value" => $form->{donumber}) .
       qq|      </td>
              </tr>
              <tr>
@@ -736,7 +769,7 @@ print qq|     <tr>
 print qq|     <tr>
                <th align="right" nowrap>| . $locale->text('Order Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .        
+               $cgi->textfield("-name" => "ordnumber", "-size" => 11, "-value" => $form->{ordnumber}) .
       qq|      </td>
              </tr>
         <tr>
@@ -747,7 +780,7 @@ print qq|     <tr>
              <tr>
                <th align="right" nowrap>| . $locale->text('Quotation Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .        
+               $cgi->textfield("-name" => "quonumber", "-size" => 11, "-value" => $form->{quonumber}) .
       qq|      </td>
              </tr>
         <tr>
@@ -758,7 +791,7 @@ print qq|     <tr>
              <tr>
                <th align="right" nowrap>| . $locale->text('Customer Order Number') . qq|</th>
                <td> |.
-               $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .  
+               $cgi->textfield("-name" => "cusordnumber", "-size" => 11, "-value" => $form->{cusordnumber}) .
       qq|      </td>
              </tr>
              <tr>
@@ -774,21 +807,27 @@ print qq|     <tr>
   <tr>
     <td>
     </td>
-  </tr> 
+  </tr>
   $jsscript
 |;
-  print qq|<input type="hidden" name="webdav" value="$webdav">|;
+  print qq|<input type="hidden" name="webdav" value="$main::webdav">|;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   $form->{invtotal} = $form->{invsubtotal};
 
+  my ($rows, $introws);
   if (($rows = $form->numtextrows($form->{notes}, 26, 8)) < 2) {
     $rows = 2;
   }
@@ -796,23 +835,24 @@ sub form_footer {
     $introws = 2;
   }
   $rows = ($rows > $introws) ? $rows : $introws;
-  $notes =
+  my $notes =
     qq|<textarea name="notes" rows="$rows" cols="26" wrap="soft">$form->{notes}</textarea>|;
-  $intnotes =
+  my $intnotes =
     qq|<textarea name="intnotes" rows="$rows" cols="35" wrap="soft">$form->{intnotes}</textarea>|;
 
   $form->{taxincluded} = ($form->{taxincluded} ? "checked" : "");
 
-  $taxincluded = "";
+  my $taxincluded = "";
   if ($form->{taxaccounts}) {
     $taxincluded = qq|
                <input name="taxincluded" class="checkbox" type="checkbox" $form->{taxincluded}> <b>|
       . $locale->text('Tax Included') . qq|</b><br><br>|;
   }
 
+  my ($tax, $subtotal);
   if (!$form->{taxincluded}) {
 
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{"${item}_total"} =
           $form->round_amount(
@@ -845,7 +885,7 @@ sub form_footer {
   }
 
   if ($form->{taxincluded}) {
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{"${item}_total"} =
           $form->round_amount(
@@ -947,7 +987,8 @@ sub form_footer {
     </td>
   </tr>
 |;
-  if ($webdav) {
+  my $webdav_list;
+  if ($main::webdav) {
     $webdav_list = qq|
   <tr>
     <td><hr size="3" noshade></td>
@@ -959,7 +1000,7 @@ sub form_footer {
       <td align="left" width="30%"><b>Dateiname</b></td>
       <td align="left" width="70%"><b>Webdavlink</b></td>
 |;
-    foreach $file (@{ $form->{WEBDAV} }) {
+    foreach my $file (@{ $form->{WEBDAV} }) {
       $webdav_list .= qq|
       <tr>
         <td align="left">$file->{name}</td>
@@ -996,12 +1037,14 @@ if ($form->{type} eq "credit_note") {
 |;
 }
 
+  my @column_index;
   if ($form->{currency} eq $form->{defaultcurrency}) {
     @column_index = qw(datepaid source memo paid AR_paid);
   } else {
     @column_index = qw(datepaid source memo paid exchangerate AR_paid);
   }
 
+  my %column_data;
   $column_data{datepaid}     = "<th>" . $locale->text('Date') . "</th>";
   $column_data{paid}         = "<th>" . $locale->text('Amount') . "</th>";
   $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
@@ -1021,7 +1064,7 @@ if ($form->{type} eq "credit_note") {
   my $totalpaid = 0;
 
   $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
 
     print "
         <tr>\n";
@@ -1042,7 +1085,7 @@ if ($form->{type} eq "credit_note") {
     if ($form->{"exchangerate_$i"} == 0) {
       $form->{"exchangerate_$i"} = "";
     }
-    $exchangerate = qq|&nbsp;|;
+    my $exchangerate = qq|&nbsp;|;
     if ($form->{currency} ne $form->{defaultcurrency}) {
       if ($form->{"forex_$i"}) {
         $exchangerate = qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
@@ -1109,8 +1152,8 @@ if ($form->{type} eq "credit_note") {
 </table>
 |;
 
-  $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
-  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+  my $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
+  my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
 
   if ($form->{id}) {
     my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ar") && (($totalpaid == 0) || ($totalpaid eq ""));
@@ -1187,10 +1230,10 @@ if ($form->{type} eq "credit_note") {
          . qq|"> |;
   }
   # /button for saving history
-  
-  # mark_as_paid button 
-  if($form->{id} ne "") {  
-    print qq|<input type="submit" class="submit" name="action" value="| 
+
+  # mark_as_paid button
+  if($form->{id} ne "") {
+    print qq|<input type="submit" class="submit" name="action" value="|
           . $locale->text('mark as paid') . qq|">|;
   }
   # /mark_as_paid button
@@ -1211,48 +1254,54 @@ $cgi->hidden("-name" => "callback", "-value" => $form->{callback})
  </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub mark_as_paid {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
-  &mark_as_paid_common(\%myconfig,"ar");  
+  &mark_as_paid_common(\%myconfig,"ar");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('invoice_edit');
 
   my ($recursive_call) = shift;
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
 
   $form->{print_and_post} = 0         if $form->{second_run};
-  $taxincluded            = "checked" if $form->{taxincluded};
+  my $taxincluded            = "checked" if $form->{taxincluded};
   $form->{update} = 1;
 
-  &check_name(customer);
+  &check_name("customer");
 
   $form->{taxincluded} ||= $taxincluded;
 
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     next unless $form->{"paid_$i"};
     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
     $form->{"forex_$i"}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
     $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
   }
 
-  $i            = $form->{rowcount};
-  $exchangerate = $form->{exchangerate} || 1;
+  my $i            = $form->{rowcount};
+  my $exchangerate = $form->{exchangerate} || 1;
 
   # if last row empty, check the form otherwise retrieve new item
   if (   ($form->{"partnumber_$i"} eq "")
@@ -1266,7 +1315,7 @@ sub update {
 
     IS->retrieve_item(\%myconfig, \%$form);
 
-    $rows = scalar @{ $form->{item_list} };
+    my $rows = scalar @{ $form->{item_list} };
 
     $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{customer_discount} * 100);
 
@@ -1280,18 +1329,18 @@ sub update {
 
       } else {
 
-        $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+        my $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
 
         map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g } qw(partnumber description unit);
         map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
-        
+
         $form->{payment_id}    = $form->{"part_payment_id_$i"} if $form->{"part_payment_id_$i"} ne "";
         $form->{"discount_$i"} = 0                             if $form->{"not_discountable_$i"};
 
         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
 
         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
-        $decimalplaces = max 2, length $1;
+        my $decimalplaces = max 2, length $1;
 
         if ($sellprice) {
           $form->{"sellprice_$i"} = $sellprice;
@@ -1303,7 +1352,7 @@ sub update {
 
         $form->{"listprice_$i"} /= $exchangerate;
 
-        $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+        my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
         map { $form->{"${_}_base"} = 0 }                                 split / /, $form->{taxaccounts};
         map { $form->{"${_}_base"} += $amount }                          split / /, $form->{"taxaccounts_$i"};
         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded};
@@ -1314,10 +1363,10 @@ sub update {
 
         $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
-        if ($lizenzen) {
+        if ($main::lizenzen) {
           if ($form->{"inventory_accno_$i"} ne "") {
             $form->{"lizenzen_$i"} = qq|<option></option>|;
-            foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
+            foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
               $form->{"lizenzen_$i"} .= qq|<option value="$item->{"id"}">$item->{"licensenumber"}</option>|;
             }
             $form->{"lizenzen_$i"} .= qq|<option value=-1>Neue Lizenz</option>|;
@@ -1351,18 +1400,24 @@ sub update {
       }
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post_payment {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('invoice_edit');
 
-  $auth->assert('invoice_edit');
+  our $invdate;
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->{"paid_$i"}) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -1386,13 +1441,17 @@ sub post_payment {
     $form->error($locale->text('Cannot post payment!'));
 
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('invoice_edit');
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
   $form->isblank("invdate",  $locale->text('Invoice Date missing!'));
@@ -1404,7 +1463,7 @@ sub post {
   $form->{invnumber} =~ s/\s*$//g;
 
   # if oldcustomer ne customer redo form
-  if (&check_name(customer)) {
+  if (&check_name('customer')) {
     &update;
     exit;
   }
@@ -1414,8 +1473,8 @@ sub post {
 
   &validate_items;
 
-  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
-  $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
+  my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+  my $invdate  = $form->datetonum($form->{invdate},  \%myconfig);
 
   $form->error($locale->text('Cannot post invoice for a closed period!'))
     if ($invdate <= $closedto);
@@ -1423,9 +1482,9 @@ sub post {
   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
     if ($form->{currency} ne $form->{defaultcurrency});
 
-  for $i (1 .. $form->{paidaccounts}) {
+  for my $i (1 .. $form->{paidaccounts}) {
     if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
-      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
+      my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
 
       $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
 
@@ -1474,28 +1533,33 @@ sub post {
   $form->redirect( $form->{label} . " $form->{invnumber} " . $locale->text('posted!'))
     unless $print_post;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_and_post {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
-  $old_form               = new Form;
+  my $old_form               = new Form;
   $print_post             = 1;
   $form->{print_and_post} = 1;
   &post();
 
   &edit();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub use_as_template {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
   $form->{paidaccounts} = 1;
@@ -1503,13 +1567,17 @@ sub use_as_template {
   $form->{invdate} = $form->current_date(\%myconfig);
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub storno {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('invoice_edit');
 
   if ($form->{storno}) {
     $form->error($locale->text('Cannot storno storno invoice!'));
@@ -1536,27 +1604,32 @@ sub storno {
   $form->{rowcount}++;
 
   post();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub preview {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   $form->{preview} = 1;
-  $old_form = new Form;
+  my $old_form = new Form;
   for (keys %$form) { $old_form->{$_} = $form->{$_} }
 
   &print_form($old_form);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   if ($form->{second_run}) {
     $form->{print_and_post} = 0;
@@ -1572,7 +1645,7 @@ sub delete {
   # delete action variable
   map { delete $form->{$_} } qw(action header);
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
@@ -1592,13 +1665,17 @@ sub delete {
 </form>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub credit_note {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('invoice_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  $main::auth->assert('invoice_edit');
 
   $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig);
   $form->{duedate} =
@@ -1611,8 +1688,8 @@ sub credit_note {
 
   $form->{title}  = $locale->text('Add Credit Note');
   $form->{script} = 'is.pl';
-  $script         = "is";
-  $buysell        = 'buy';
+  our $script         = "is";
+  our $buysell        = 'buy';
 
 
   # bo creates the id, reset it
@@ -1622,12 +1699,12 @@ sub credit_note {
   $form->{type} = "credit_note";
 
 
-  map { $form->{"select$_"} = "" } ($form->{vc}, currency);
+  map { $form->{"select$_"} = "" } ($form->{vc}, 'currency');
 
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(creditlimit creditremaining);
 
-  $currency = $form->{currency};
+  my $currency = $form->{currency};
   &invoice_links;
 
   $form->{currency}     = $currency;
@@ -1641,15 +1718,19 @@ sub credit_note {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
-  if (IS->delete_invoice(\%myconfig, \%$form, $spool)) {
+  if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
     # saving the history
        if(!exists $form->{addition}) {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
@@ -1661,13 +1742,15 @@ sub yes {
   }
   $form->error($locale->text('Cannot delete invoice!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub e_mail {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
-  $auth->assert('invoice_edit');
+  $main::auth->assert('invoice_edit');
 
   if (!$form->{id}) {
     $print_post = 1;
@@ -1681,5 +1764,5 @@ sub e_mail {
 
   edit_e_mail();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index ea7e5d3..b5a895a 100644 (file)
@@ -5,15 +5,21 @@ $| = 1;
 
 use CGI::Carp qw(fatalsToBrowser);
 
+use strict;
+
+my $form     = $main::form;
+my $locale   = $main::locale;
+
 $form->header;
-$paramstring = $ENV{"QUERY_STRING"};
-@felder = split "&", $paramstring;
+my $paramstring = $ENV{"QUERY_STRING"};
+my @felder = split "&", $paramstring;
+my ($name, $wert);
 foreach (@felder) {
   ($name, $wert) = split "=", $_;
   $wert =~ tr/+/ /;
-  $$name = $wert;
+  $name = $wert;
 }
-$login =
+my $login =
     "[" . $form->{login}
   . " - <a href=\"login.pl?action=logout\" target=\"_top\">"
   . $locale->text('Logout')
@@ -33,7 +39,7 @@ my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
                    "April",  "Mai",       "Juni",    "Juli",
                    "August", "September", "Oktober", "November",
                    "Dezember");
-$datum =
+my $datum =
     $Wochentage[$Wochentag] . ", der "
   . $Monatstag . "."
   . $Monat . "."
index 5876e85..591608b 100644 (file)
@@ -37,17 +37,21 @@ use SL::LICENSES;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 sub quot {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
   $_[0] =~ s/\"/\&quot;/g;
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
   return $_[0];
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
 
   $form->{jsscript} = 1;
   $form->header();
@@ -56,13 +60,15 @@ sub form_header {
     qq|<body>
 
 <form method=post action=$form->{script}>|);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
 
   my @items = qw(old_callback previousform);
   push(@items, @{ $form->{"hidden"} });
@@ -76,19 +82,25 @@ sub form_footer {
 </body>
 </html>
 |);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub set_std_hidden {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+
   $form->{"hidden"} = ["comment", "validuntil", "quantity", @_];
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_part_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('license_edit');
+  $main::auth->assert('license_edit');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   form_header();
   set_std_hidden("business");
@@ -109,9 +121,10 @@ sub print_part_selection {
   </tr>
         |);
 
-  $j = 1;
-  for ($i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
-    %p = %{ $form->{"parts"}->[$i - 1] };
+  my $j = 1;
+  for (my $i = 1; $i <= scalar(@{ $form->{"parts"} }); $i++) {
+    my %p = %{ $form->{"parts"}->[$i - 1] };
+    my $checked;
     if ($i == 1) {
       $checked = "checked";
     } else {
@@ -139,13 +152,16 @@ sub print_part_selection {
 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_customer_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   form_header();
   set_std_hidden("parts_id", "partnumber", "description");
@@ -170,9 +186,10 @@ sub print_customer_selection {
 
   print(qq|<tr><td colspan=6><hr size=3 noshade></td></tr>|);
 
-  $j = 1;
-  for ($i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
-    %c = %{ $form->{"all_customers"}->[$i - 1] };
+  my $j = 1;
+  for (my $i = 1; $i <= scalar(@{ $form->{"all_customers"} }); $i++) {
+    my %c = %{ $form->{"all_customers"}->[$i - 1] };
+    my $checked;
     if ($i == 1) {
       $checked = "checked";
     } else {
@@ -202,13 +219,17 @@ sub print_customer_selection {
 <input type=submit name=action value=| . $locale->text('Continue') . qq|>|);
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_license_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('license_edit');
+  $main::auth->assert('license_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   print(
     qq|
@@ -236,7 +257,7 @@ sub print_license_form {
       if (!defined($form->{"customer_id"})) {
         $form->{"customer_id"} = $_->{"id"};
       }
-      $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
+      my $selected = ($_->{"id"} * 1) == $form->{"customer_id"} ? "selected" : "";
       print(qq|<option $selected> $_->{"name"}--$_->{"id"}</option>|);
     }
     print(qq|</select></td>|);
@@ -291,15 +312,18 @@ sub print_license_form {
     $form->write_trigger(\%myconfig, 1, "validuntil", "BL",
                          "trigger_validuntil"));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  if (!$lizenzen) {
+  if (!$main::lizenzen) {
     $form->error(
                  $locale->text(
                    'The licensing module has been deactivated in lx-erp.conf.')
@@ -309,19 +333,22 @@ sub add {
   $form->{"initial"} = 1;
 
   do_add();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub do_add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('license_edit');
+  $main::auth->assert('license_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{"hidden"} = ["parts_id"];
   form_header();
 
   if ($form->{"ndx"}) {
-    $ndx = $form->{"ndx"};
+    my $ndx = $form->{"ndx"};
     foreach (keys(%{$form})) {
       next unless (/^new_.*_${ndx}$/);
       s/^new_//;
@@ -337,7 +364,7 @@ sub do_add {
   if ($form->{"customer_name"}) {
     LICENSES->get_customers(\%myconfig, $form);
     if (scalar(@{ $form->{"all_customers"} }) == 1) {
-      %c                       = %{ $form->{"all_customers"}->[0] };
+      my %c                       = %{ $form->{"all_customers"}->[0] };
       $form->{"customer_id"}   = $c{"id"};
       $form->{"customer_name"} = $c{"name"};
     } elsif (scalar(@{ $form->{"all_customers"} }) == 0) {
@@ -376,29 +403,38 @@ sub do_add {
   print_license_form($form->{"parts_id"} && $form->{"customer_id"});
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
 
   do_add();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub continue {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+
   call_sub($form->{"nextsub"});
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('license_edit');
+  $main::auth->assert('license_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   ($form->{customername}, $form->{customer_id}) = split /--/,
     $form->{customer};
@@ -415,22 +451,23 @@ sub save {
     $form->error($locale->text('Please enter a license key.'));
   }
 
-  $rc = LICENSES->save_license(\%myconfig, \%$form);
+  my $rc = LICENSES->save_license(\%myconfig, \%$form);
 
   # load previous variables
   if ($form->{previousform}) {
 
     # save the new form variables before splitting previousform
+    my %newform;
     map { $newform{$_} = $form->{$_} } keys %$form;
 
-    $previousform = $form->unescape($form->{previousform});
+    my $previousform = $form->unescape($form->{previousform});
 
     # don't trample on previous variables
     map { delete $form->{$_} } keys %newform;
 
     # now take it apart and restore original values
-    foreach $item (split /&/, $previousform) {
-      ($key, $value) = split /=/, $item, 2;
+    foreach my $item (split /&/, $previousform) {
+      my ($key, $value) = split /=/, $item, 2;
       $value =~ s/%26/&/g;
       $form->{$key} = $value;
     }
@@ -442,16 +479,16 @@ sub save {
     delete $form->{action};
 
     # restore original callback
-    $callback = $form->unescape($form->{callback});
+    my $callback = $form->unescape($form->{callback});
     $form->{callback} = $form->unescape($form->{old_callback});
     delete $form->{old_callback};
 
     # put callback together
-    foreach $key (keys %$form) {
+    foreach my $key (keys %$form) {
       next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
 
       # do single escape for Apache 2.0
-      $value = $form->escape($form->{$key}, 1);
+      my $value = $form->escape($form->{$key}, 1);
       $callback .= qq|&$key=$value|;
     }
     $form->{callback} = $callback;
@@ -466,15 +503,18 @@ sub save {
     form_footer();
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
-  if (!$lizenzen) {
+  if (!$main::lizenzen) {
     $form->error(
                  $locale->text(
                    'The licensing module has been deactivated in lx-erp.conf.')
@@ -524,25 +564,30 @@ sub search {
         |);
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub do_search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('license_edit');
+  $main::auth->assert('license_edit');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   LICENSES->search(\%myconfig, $form);
 
-  $callback = "";
+  my $callback = "";
   map { $callback .= "\&${_}=" . $form->escape($form->{$_}, 1) }
     qw(db partnumber description customer_name all expiring_in show_expired);
-  $details    = $form->{"script"} . "?action=details" . $callback . "\&id=";
-  $invdetails = "is.pl?action=edit" . $callback . "\&id=";
+  my $details    = $form->{"script"} . "?action=details" . $callback . "\&id=";
+  my $invdetails = "is.pl?action=edit" . $callback . "\&id=";
   $callback   = $form->{"script"} . "?action=do_search" . $callback;
 
   $form->{"sortby"} = "validuntil" unless ($form->{"sortby"});
   $form->{"sortasc"} *= 1;
+  my %columns;
   foreach (("partnumber", "description", "name", "validuntil", "invnumber")) {
     $columns{$_} = $callback . "\&sortby=${_}\&sortasc=";
     if ($form->{"sortby"} eq $_) {
@@ -595,9 +640,9 @@ sub do_search {
       </tr>
         |);
 
-  $j = 1;
-  for ($i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
-    $ref = $form->{"licenses"}->[$i];
+  my $j = 1;
+  for (my $i = 0; $i < scalar(@{ $form->{"licenses"} }); $i++) {
+    my $ref = $form->{"licenses"}->[$i];
     print(
       qq|
           <tr class=listrow$j>
@@ -635,13 +680,17 @@ sub do_search {
         |);
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub details {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('license_edit');
 
-  $auth->assert('license_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   LICENSES->get_license(\%myconfig, $form);
   map(
@@ -696,7 +745,7 @@ sub details {
         |);
 
   form_footer();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index 92fa25d..82d50d7 100644 (file)
@@ -35,24 +35,26 @@ use SL::Form;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/todo.pl";
 
+use strict;
+
 # This is required because the am.pl in the root directory
 # is not scanned by locales.pl:
 # $form->parse_html_template('login/password_error')
 
-$form = new Form;
+our $form = new Form;
 
 if (! -f 'config/authentication.pl') {
   show_error('login/authentication_pl_missing');
 }
 
-$locale = new Locale $language, "login";
+our $locale = new Locale $main::language, "login";
 
 our $auth = SL::Auth->new();
 if (!$auth->session_tables_present()) {
   show_error('login/auth_db_unreachable');
 }
 $auth->expire_sessions();
-my $session_result = $auth->restore_session();
+my $session_result = $main::auth->restore_session();
 
 # customization
 if (-f "bin/mozilla/custom_$form->{script}") {
@@ -103,7 +105,7 @@ if ($action) {
 1;
 
 sub login_screen {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
   my ($msg) = @_;
 
   if (-f "css/lx-office-erp.css") {
@@ -115,20 +117,21 @@ sub login_screen {
 
   print $form->parse_html_template('login/login_screen');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub login {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   unless ($form->{login}) {
     login_screen($locale->text('You did not enter a name!'));
     exit;
   }
 
-  $user = new User $form->{login};
+  my $user = new User $form->{login};
 
   # if we get an error back, bale out
+  my $result;
   if (($result = $user->login($form)) <= -1) {
     exit if $result == -2;
     login_screen($locale->text('Incorrect username or password!'));
@@ -146,29 +149,30 @@ sub login {
   # made it this far, execute the menu
   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display', "callback=" . $form->escape($form->{callback}));
 
-  $auth->set_cookie_environment_variable();
+  $main::auth->set_cookie_environment_variable();
 
   $form->redirect();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub logout {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->destroy_session();
+  $main::auth->destroy_session();
 
   # remove the callback to display the message
   $form->{callback} = "login.pl?action=";
   $form->redirect($locale->text('You are logged out!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub company_logo {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
+  my %myconfig = %main::myconfig;
+  $locale             =  new Locale $myconfig{countrycode}, "login" if ($main::language ne $myconfig{countrycode});
 
   $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
 
@@ -180,13 +184,14 @@ sub company_logo {
 
   print $form->parse_html_template('login/company_logo');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub show_error {
   my $template           = shift;
-  $locale                = Locale->new($language, 'all');
-  $myconfig{countrycode} = $language;
+  my %myconfig = %main::myconfig;
+  $locale                = Locale->new($main::language, 'all');
+  $myconfig{countrycode} = $main::language;
   $form->{stylesheet}    = 'css/lx-office-erp.css';
 
   $form->header();
index a8b4697..07ad110 100644 (file)
 #  2004-12-14 - New Optik - Marco Welter <mawe@linux-studio.de>
 #######################################################################
 
-$menufile = "menu.ini";
+my $menufile = "menu.ini";
 use SL::Menu;
 use Data::Dumper;
 use URI;
 
+use strict;
+
+my $framesize = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "190";
+my $mainlevel;
+
 1;
 
 # end of main
 
-$framesize = ($ENV{HTTP_USER_AGENT} =~ /links/i) ? "240" : "190";
-
 sub display {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $callback   = $form->unescape($form->{callback});
   $callback      = URI->new($callback)->rel($callback) if $callback;
@@ -69,11 +74,15 @@ sub display {
 </HTML>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub acc_menu {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   $mainlevel = $form->{level};
   $mainlevel =~ s/\Q$mainlevel\E--//g;
   my $menu = new Menu "$menufile";
@@ -98,34 +107,40 @@ sub acc_menu {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub section_menu {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
   my ($menu, $level) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  my $zeige;
+
   # build tiered menus
   my @menuorder = $menu->access_control(\%myconfig, $level);
   while (@menuorder) {
-    $item  = shift @menuorder;
-    $label = $item;
-    $ml    = $item;
+    my $item  = shift @menuorder;
+    my $label = $item;
+    my $ml    = $item;
     $label =~ s/\Q$level\E--//g;
     $ml    =~ s/--.*//;
     if ($ml eq $mainlevel) { $zeige = 1; }
     else { $zeige = 0; }
     my $spacer = "&nbsp;" x (($item =~ s/--/--/g) * 1);
     $label =~ s/.*--//g;
-    $label_icon = $label . ".gif";
-    $mlab       = $label;
+    my $label_icon = $label . ".gif";
+    my $mlab       = $label;
     $label      = $locale->text($label);
 
     # multi line hack, sschoeling jul06
     # if a label is too long, try to split it at whitespaces, then join it to chunks of less
     # than 20 chars and store it in an array.
     # use this array later instead of the &nbsp;-ed label
-    @chunks = ();
+    my @chunks = ();
     my ($i,$l) = (-1, 20);
     map {
       if (($l += length $_) < 20) {
@@ -211,5 +226,5 @@ sub section_menu {
       }
     }
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index 1d9b0ac..5744c84 100644 (file)
 #  2007-10-14 - XMLified  - Holger Will  <holger@treebuilder.de>
 #######################################################################
 
-$menufile = "menu.ini";
+my $menufile = "menu.ini";
 use SL::Menu;
 
 use CGI::Carp qw(fatalsToBrowser);
 use Encode;
 use URI;
+
+use strict;
+
+my $locale;
+
 1;
 
 # end of main
 
 sub display {
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $locale     = Locale->new($myconfig{countrycode}, "menu");
-  my $charset = $dbcharset || 'ISO-8859-1';
+  my $charset = $main::dbcharset || 'ISO-8859-1';
   my $callback            = $form->unescape($form->{callback});
   $callback               = URI->new($callback)->rel($callback) if $callback;
   $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
@@ -89,7 +97,9 @@ sub display {
 
 
 sub acc_menu {
-  $mainlevel = $form->{level};
+  my $form     = $main::form;
+
+  my $mainlevel = $form->{level};
   $mainlevel =~ s/$mainlevel--//g;
   my $menu = new Menu "$menufile";
 
@@ -102,6 +112,9 @@ sub print_menu {
   my ($menu, $parent, $depth) = @_;
   my $html;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   die if ($depth * 1 > 5);
 
   my @menuorder;
index b948ef2..f4455d6 100644 (file)
 #  2004-12-14 - Holger Lindemann
 #######################################################################
 
-$menufile = "menu.ini";
+my $menufile = "menu.ini";
 use SL::Menu;
 use CGI::Carp qw(fatalsToBrowser);
 
+use strict;
+
+my $locale;
+
 1;
 
 # end of main
 
 sub display {
+
+  my $form     = $main::form;
+
   $form->{callback}   = $form->unescape($form->{callback});
   $form->{callback} ||= "login.pl?action=company_logo";
 
@@ -67,10 +74,12 @@ sub display {
 
 sub clock_line {
 
-  $fensterlink="menujs.pl?action=display";
-  $fenster = "["."<a href=\"$fensterlink\" target=\"_blank\">neues Fenster</a>]";
+  my $form     = $main::form;
 
-  $login = "[Nutzer "
+  my $fensterlink="menujs.pl?action=display";
+  my $fenster = "["."<a href=\"$fensterlink\" target=\"_blank\">neues Fenster</a>]";
+
+  my $login = "[Nutzer "
     . $form->{login}
     . " - <a href=\"login.pl?action=logout\" target=\"_top\">"
     . $locale->text('Logout')
@@ -90,14 +99,14 @@ sub clock_line {
                      "April",  "Mai",       "Juni",    "Juli",
                      "August", "September", "Oktober", "November",
                      "Dezember");
-  $datum =
+  my $datum =
       $Wochentage[$Wochentag] . ", der "
     . $Monatstag . "."
     . $Monat . "."
     . $Jahr . " - ";
 
   #$zeit="<div id='Uhr'>".$Stunden.":".$Minuten.":".$Sekunden."</div>";
-  $zeit = "<div id='Uhr'>" . $Stunden . ":" . $Minuten . "</div>";
+  my $zeit = "<div id='Uhr'>" . $Stunden . ":" . $Minuten . "</div>";
   print qq|
 <script type="text/javascript">
 <!--
@@ -123,8 +132,12 @@ window.onload=clockon
 }
 
 sub acc_menu {
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $locale = Locale->new($myconfig{countrycode}, "menu");
-  $mainlevel = $form->{level};
+  my $mainlevel = $form->{level};
   $mainlevel =~ s/$mainlevel--//g;
   my $menu = new Menu "$menufile";
 
@@ -361,16 +374,20 @@ function moveRoot() {
 sub section_menu {
   my ($menu, $level) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   # build tiered menus
   my @menuorder = $menu->access_control(\%myconfig, $level);
-  $main = 0;
+  my $main = 0;
 
   #$pm=0;
-  $shlp=0;
+  my $shlp=0;
+  my (%mlz, $sm, $z, $pm, $mm);
   while (@menuorder) {
-    $item  = shift @menuorder;
-    $label = $item;
-    $ml    = $item;
+    my $item  = shift @menuorder;
+    my $label = $item;
+    my $ml    = $item;
     $label =~ s/$level--//g;
     $ml    =~ s/--.*//;
     $label = $locale->text($label);
@@ -403,8 +420,8 @@ sub section_menu {
       if ($menu->{$item}{module}) {
 
         #Untermenüpunkte
-        $target = $menu->{$item}{target};
-        $uri    = $menu->menuitem_js(\%myconfig, \%$form, $item, $level);
+        my $target = $menu->{$item}{target};
+        my $uri    = $menu->menuitem_js(\%myconfig, \%$form, $item, $level);
 
         print
           qq|menu[$pm][$sm] = new Item('$label', '$uri', '$target', defLength, 0, 0);\n|;
@@ -416,7 +433,7 @@ sub section_menu {
         %mlz   = ($ml, $pm, "s$ml", 1);
         $shlp = $sm;
         $sm    = 1;
-        $breit = 15 + length($label) * 6;
+        my $breit = 15 + length($label) * 6;
         print
           qq|menu[0][$mm] = new Item('  $label', '#', '', $breit, 10, $pm);    \n|;
         print qq|menu[$pm] = new Array();\n|;
index 777c38c..793cec2 100644 (file)
@@ -38,11 +38,17 @@ use URI;
 
 use SL::Menu;
 
+use strict;
+
+my $locale;
+
 1;
 
 # end of main
 
 sub display {
+  my $form     = $main::form;
+
   $form->header();
 
 #   $form->{force_ul_width} = $ENV{HTTP_USER_AGENT} =~ m/MSIE\s+6\./;
@@ -59,6 +65,8 @@ sub display {
 }
 
 sub clock_line {
+  my $form     = $main::form;
+
   my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
       $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
     = localtime(time);
@@ -81,13 +89,15 @@ sub clock_line {
 }
 
 sub acc_menu {
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
   $locale = Locale->new($myconfig{countrycode}, "menu");
 
   my $mainlevel =  $form->{level};
   $mainlevel    =~ s/\Q$mainlevel\E--//g;
   my $menu      = Menu->new('menu.ini');
 
-  $AUTOFLUSH    =  1;
+  $English::AUTOFLUSH    =  1;
 
   my $all_items = [];
   create_menu($menu, $all_items);
@@ -112,6 +122,9 @@ sub create_menu {
   my ($menu, $all_items, $parent, $depth) = @_;
   my $html;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   die if ($depth * 1 > 5);
 
   my @menuorder  = $menu->access_control(\%myconfig, $parent);
index 02a465e..683cabf 100644 (file)
 #
 #######################################################################
 
-$menufile = "menu.ini";
 use SL::Menu;
 use URI;
 
+use strict;
+
+my $menufile = "menu.ini";
+my $locale;
+
 1;
 
 # end of main
 
 sub display {
+  my $form     = $main::form;
+
   $form->header(qq|<link rel="stylesheet" href="css/menuv3.css?id=" type="text/css">|);
 
   $form->{date}     = clock_line();
@@ -77,9 +83,12 @@ sub clock_line {
 }
 
 sub acc_menu {
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $locale = Locale->new($myconfig{countrycode}, "menu");
 
-  $mainlevel = $form->{level};
+  my $mainlevel = $form->{level};
   $mainlevel =~ s/\Q$mainlevel\E--//g;
   my $menu = new Menu "$menufile";
 
@@ -90,6 +99,10 @@ sub acc_menu {
 
 sub print_menu {
   my ($menu, $parent, $depth) = @_;
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $html;
 
   die if ($depth * 1 > 5);
index 0420fee..3b736bf 100644 (file)
 #
 #######################################################################
 
-$menufile = "menu.ini";
 use SL::Menu;
 use URI;
 
+use strict;
+
+my $menufile = "menu.ini";
+my $locale;
+
 1;
 
 # end of main
 
 sub display {
+  my $form     = $main::form;
+
   $form->header(qq|<link rel="stylesheet" href="css/menuv4.css?id=" type="text/css">|);
 
   $form->{date}     = clock_line();
@@ -55,6 +61,8 @@ sub display {
 }
 
 sub clock_line {
+  my $form     = $main::form;
+
   my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
       $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
     = localtime(time);
@@ -77,9 +85,12 @@ sub clock_line {
 }
 
 sub acc_menu {
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   $locale = Locale->new($myconfig{countrycode}, "menu");
 
-  $mainlevel = $form->{level};
+  my $mainlevel = $form->{level};
   $mainlevel =~ s/\Q$mainlevel\E--//g;
   my $menu = new Menu "$menufile";
 
@@ -90,6 +101,10 @@ sub acc_menu {
 
 sub print_menu {
   my ($menu, $parent, $depth) = @_;
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $html;
 
   die if ($depth * 1 > 5);
index e47ffee..116d168 100644 (file)
@@ -48,6 +48,11 @@ require "bin/mozilla/io.pl";
 require "bin/mozilla/arap.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
+my $print_post;
+my %TMPL_VAR;
+
 1;
 
 # end of main
@@ -71,14 +76,19 @@ my $oe_access_map = {
 };
 
 sub check_oe_access {
+  my $form     = $main::form;
+
   my $right   = $oe_access_map->{$form->{type}};
   $right    ||= 'DOES_NOT_EXIST';
 
-  $auth->assert($right);
+  $main::auth->assert($right);
 }
 
 sub set_headings {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -113,11 +123,13 @@ sub set_headings {
     $form->{vc}      = 'customer';
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -131,11 +143,13 @@ sub add {
   &prepare_order;
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -149,21 +163,23 @@ sub edit {
 
   # editing without stuff to edit? try adding it first
   if ($form->{rowcount} && !$form->{print_and_save}) {
+    my $id;
     map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount});
     if (!$id) {
 
       # reset rowcount
       undef $form->{rowcount};
       &add;
-      $lxdebug->leave_sub();
+      $main::lxdebug->leave_sub();
       return;
     }
   } elsif (!$form->{id}) {
     &add;
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
+  my ($language_id, $printer_id);
   if ($form->{print_and_save}) {
     $form->{action}   = "print";
     $form->{resubmit} = 1;
@@ -176,7 +192,7 @@ sub edit {
   &order_links;
 
   $form->{rowcount} = 0;
-  foreach $ref (@{ $form->{form_details} }) {
+  foreach my $ref (@{ $form->{form_details} }) {
     $form->{rowcount}++;
     map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
   }
@@ -190,11 +206,15 @@ sub edit {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub order_links {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -202,7 +222,7 @@ sub order_links {
   $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
 
   # retrieve order/quotation
-  $form->{webdav}   = $webdav;
+  $form->{webdav}   = $main::webdav;
   $form->{jsscript} = 1;
 
   my $editing = $form->{id};
@@ -243,11 +263,14 @@ sub order_links {
     $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}|
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub prepare_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   check_oe_access();
 
@@ -263,13 +286,18 @@ sub prepare_order {
     $form->{"qty_$i"}       = $form->format_amount(\%myconfig, $form->{"qty_$i"});
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
   my @custom_hiddens;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
+
   check_oe_access();
 
   # Container for template variables. Unfortunately this has to be visible in form_footer too, so not my.
@@ -325,8 +353,8 @@ sub form_header {
   push @custom_hiddens, "select$form->{vc}";
 
   # currencies and exchangerate
-  @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
-  %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
+  my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
+  my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
   $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
   $TMPL_VAR{currencies}        = NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
@@ -335,7 +363,7 @@ sub form_header {
   push @custom_hiddens, "exchangerate" if $form->{forex};
 
   # credit remaining
-  $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
+  my $creditwarning = (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) ? 1 : 0;
   $TMPL_VAR{is_credit_remaining_negativ} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
 
   # business
@@ -343,7 +371,7 @@ sub form_header {
 
   push @custom_hiddens, "customer_klass" if $form->{vc} eq 'customer';
 
-  $credittext = $locale->text('Credit Limit exceeded!!!');
+  my $credittext = $locale->text('Credit Limit exceeded!!!');
 
   my $follow_up_vc                =  $form->{ $form->{vc} eq 'customer' ? 'customer' : 'vendor' };
   $follow_up_vc                   =~ s/--\d*\s*$//;
@@ -358,7 +386,7 @@ sub form_header {
     }
   }
 
-  $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
+  my $onload = ($form->{resubmit} && ($form->{format} eq "html")) ? "window.open('about:blank','Beleg'); document.oe.target = 'Beleg';document.oe.submit()"
           : ($form->{resubmit})                                ? "document.oe.submit()"
           : ($creditwarning)                                   ? "alert('$credittext')"
           :                                                      "";
@@ -395,18 +423,22 @@ sub form_header {
 
   print $form->parse_html_template("oe/form_header", { %TMPL_VAR });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
   $form->{invtotal} = $form->{invsubtotal};
 
-  $rows    = max 2, $form->numtextrows($form->{notes}, 25, 8);
-  $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
+  my $rows    = max 2, $form->numtextrows($form->{notes}, 25, 8);
+  my $introws = max 2, $form->numtextrows($form->{intnotes}, 35, 8);
   $rows    = max $rows, $introws;
 
   $TMPL_VAR{notes}    = qq|<textarea name=notes rows=$rows cols=25 wrap=soft>| . H($form->{notes}) . qq|</textarea>|;
@@ -414,7 +446,7 @@ sub form_footer {
 
   if (!$form->{taxincluded}) {
 
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount( $form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
         $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
@@ -430,7 +462,7 @@ sub form_footer {
 #    $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this
 
   } else {
-    foreach $item (split / /, $form->{taxaccounts}) {
+    foreach my $item (split / /, $form->{taxaccounts}) {
       if ($form->{"${item}_base"}) {
         $form->{"${item}_total"} = $form->round_amount( ($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})), 2);
         $form->{"${item}_netto"} = $form->round_amount( ($form->{"${item}_base"} - $form->{"${item}_total"}), 2);
@@ -454,20 +486,23 @@ sub form_footer {
 
   print $form->parse_html_template("oe/form_footer", {
      %TMPL_VAR,
-     webdav          => $webdav,
+     webdav          => $main::webdav,
      print_options   => print_options(inline => 1),
      label_edit      => $locale->text("Edit the $form->{type}"),
      label_workflow  => $locale->text("Workflow $form->{type}"),
   });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($recursive_call) = shift;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   check_oe_access();
 
 #  $main::lxdebug->message(0, Dumper($form));
@@ -477,22 +512,22 @@ sub update {
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call;
   $form->{update} = 1;
 
-  $payment_id = $form->{payment_id} if $form->{payment_id};
+  my $payment_id = $form->{payment_id} if $form->{payment_id};
 
   &check_name($form->{vc});
 
   $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
 
-  $buysell              = 'buy';
+  my $buysell           = 'buy';
   $buysell              = 'sell' if ($form->{vc} eq 'vendor');
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
-  $exchangerate = $form->{exchangerate} || 1;
+  my $exchangerate = $form->{exchangerate} || 1;
 
 ##################### process items ######################################
   # for pricegroups
-  $i = $form->{rowcount};
+  my $i = $form->{rowcount};
   if (   ($form->{"partnumber_$i"} eq "")
       && ($form->{"description_$i"} eq "")
       && ($form->{"partsgroup_$i"}  eq "")) {
@@ -526,7 +561,7 @@ sub update {
 
       } else {
 
-        $sellprice             = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
+        my $sellprice             = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
         # hier werden parts (Artikeleigenschaften) aus item_list (retrieve_item aus IS.pm)
         # (item wahrscheinlich synonym für parts) entsprechend in die form geschrieben ...
 
@@ -543,7 +578,8 @@ sub update {
         $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
 
         ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
-        $decimalplaces = max 2, length $1;
+        my $dec_qty       = length $1;
+        my $decimalplaces = max 2, $dec_qty;
 
         if ($sellprice) {
           $form->{"sellprice_$i"} = $sellprice;
@@ -552,7 +588,7 @@ sub update {
           $form->{"sellprice_$i"} /= $exchangerate;   # if there is an exchange rate adjust sellprice
         }
 
-        $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
+        my $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
         map { $form->{"${_}_base"} = 0 }                                 split / /, $form->{taxaccounts};
         map { $form->{"${_}_base"} += $amount }                          split / /, $form->{"taxaccounts_$i"};
         map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{taxaccounts} if !$form->{taxincluded};
@@ -591,11 +627,15 @@ sub update {
 ##################### process items ######################################
 
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -645,14 +685,17 @@ sub search {
 
   print $form->parse_html_template('oe/search', { %myconfig });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
@@ -661,17 +704,22 @@ sub create_subtotal_row {
 
   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub orders {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   check_oe_access();
 
-  $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
+  my $ordnumber = ($form->{type} =~ /_order$/) ? "ordnumber" : "quonumber";
 
   ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) = split(/--/, $form->{ $form->{vc} });
 
@@ -810,7 +858,7 @@ sub orders {
   $form->{callback} = $href .= "&sort=$form->{sort}";
 
   # escape callback for href
-  $callback = $form->escape($href);
+  my $callback = $form->escape($href);
 
   my @subtotal_columns = qw(netamount amount marge_total marge_percent);
 
@@ -821,7 +869,7 @@ sub orders {
 
   my $edit_url = build_std_url('action=edit', 'type', 'vc');
 
-  foreach $oe (@{ $form->{OE} }) {
+  foreach my $oe (@{ $form->{OE} }) {
     map { $oe->{$_} *= $oe->{exchangerate} } @subtotal_columns;
 
     $oe->{tax}       = $oe->{amount} - $oe->{netamount};
@@ -873,16 +921,19 @@ sub orders {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_delivered_flag {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   check_oe_access();
 
   if (($form->{type} ne 'sales_order') && ($form->{type} ne 'purchase_order')) {
-    return $lxdebug->leave_sub();
+    return $main::lxdebug->leave_sub();
   }
 
   my $all_delivered = 0;
@@ -901,11 +952,15 @@ sub check_delivered_flag {
 
   $form->{delivered} = 1 if $all_delivered;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_and_close {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -921,7 +976,7 @@ sub save_and_close {
   $form->{$idx} =~ s/^\s*//g;
   $form->{$idx} =~ s/\s*$//g;
 
-  $msg = ucfirst $form->{vc};
+  my $msg = ucfirst $form->{vc};
   $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
 
   # $locale->text('Customer missing!');
@@ -932,6 +987,7 @@ sub save_and_close {
 
   &validate_items;
 
+  my $payment_id;
   if($form->{payment_id}) {
     $payment_id = $form->{payment_id};
   }
@@ -947,6 +1003,7 @@ sub save_and_close {
 
   $form->{id} = 0 if $form->{saveasnew};
 
+  my ($numberfld, $ordnumber, $err);
   # this is for the internal notes section for the [email] Subject
   if ($form->{type} =~ /_order$/) {
     if ($form->{type} eq 'sales_order') {
@@ -1002,11 +1059,15 @@ sub save_and_close {
   $form->redirect($form->{label} . " $form->{$ordnumber} " .
                   $locale->text('saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -1023,7 +1084,7 @@ sub save {
   $form->{$idx} =~ s/^\s*//g;
   $form->{$idx} =~ s/\s*$//g;
 
-  $msg = ucfirst $form->{vc};
+  my $msg = ucfirst $form->{vc};
   $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
 
   # $locale->text('Customer missing!');
@@ -1034,6 +1095,7 @@ sub save {
 
   &validate_items;
 
+  my $payment_id;
   if($form->{payment_id}) {
     $payment_id = $form->{payment_id};
   }
@@ -1049,6 +1111,8 @@ sub save {
 
   $form->{id} = 0 if $form->{saveasnew};
 
+  my ($numberfld, $ordnumber, $err);
+
   # this is for the internal notes section for the [email] Subject
   if ($form->{type} =~ /_order$/) {
     if ($form->{type} eq 'sales_order') {
@@ -1105,16 +1169,20 @@ sub save {
     edit();
     exit;
   }
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
   $form->header;
 
+  my ($msg, $ordnumber);
   if ($form->{type} =~ /_order$/) {
     $msg       = $locale->text('Are you sure you want to delete Order Number');
     $ordnumber = 'ordnumber';
@@ -1132,7 +1200,7 @@ sub delete {
   # delete action variable
   map { delete $form->{$_} } qw(action header);
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
@@ -1154,14 +1222,19 @@ sub delete {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete_order_quotation {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
+  my ($msg, $err);
   if ($form->{type} =~ /_order$/) {
     $msg = $locale->text('Order deleted!');
     $err = $locale->text('Cannot delete order!');
@@ -1169,7 +1242,7 @@ sub delete_order_quotation {
     $msg = $locale->text('Quotation deleted!');
     $err = $locale->text('Cannot delete quotation!');
   }
-  if (OE->delete(\%myconfig, \%$form, $spool)){
+  if (OE->delete(\%myconfig, \%$form, $main::spool)){
     # saving the history
     if(!exists $form->{addition}) {
       $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
@@ -1182,14 +1255,18 @@ sub delete_order_quotation {
   }
   $form->error($err);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub invoice {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   check_oe_access();
-  $auth->assert($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation' ? 'vendor_invoice_edit' : 'invoice_edit');
+  $main::auth->assert($form->{type} eq 'purchase_order' || $form->{type} eq 'request_quotation' ? 'vendor_invoice_edit' : 'invoice_edit');
 
   $form->{old_salesman_id} = $form->{salesman_id};
   $form->get_employee();
@@ -1214,7 +1291,7 @@ sub invoice {
     $form->{quodate}      = $form->{transdate};
   }
 
-  $payment_id = $form->{payment_id} if $form->{payment_id};
+  my $payment_id = $form->{payment_id} if $form->{payment_id};
 
   # if the name changed get new values
   if (&check_name($form->{vc})) {
@@ -1225,12 +1302,13 @@ sub invoice {
 
   $form->{cp_id} *= 1;
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     for (qw(ship qty sellprice listprice basefactor)) {
       $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"};
     }
   }
 
+  my ($buysell, $orddate, $exchangerate);
   if (   $form->{type} =~ /_order/
       && $form->{currency} ne $form->{defaultcurrency}) {
 
@@ -1260,6 +1338,7 @@ sub invoice {
     &create_backorder;
   }
 
+  my ($script);
   if (   $form->{type} eq 'purchase_order'
       || $form->{type} eq 'request_quotation') {
     $form->{title}  = $locale->text('Add Vendor Invoice');
@@ -1288,7 +1367,7 @@ sub invoice {
 
   map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
 
-  $currency = $form->{currency};
+  my $currency = $form->{currency};
   &invoice_links;
 
   $form->{currency}     = $currency;
@@ -1300,13 +1379,13 @@ sub invoice {
   &prepare_invoice;
 
   # format amounts
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     $form->{"discount_$i"} =
       $form->format_amount(\%myconfig, $form->{"discount_$i"});
 
-    ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
+    my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
     $dec           = length $dec;
-    $decimalplaces = ($dec > 2) ? $dec : 2;
+    my $decimalplaces = ($dec > 2) ? $dec : 2;
 
     # copy delivery date from reqdate for order -> invoice conversion
     $form->{"deliverydate_$i"} = $form->{"reqdate_$i"}
@@ -1328,11 +1407,14 @@ sub invoice {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub backorder_exchangerate {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   check_oe_access();
 
@@ -1349,7 +1431,7 @@ sub backorder_exchangerate {
   # delete action variable
   map { delete $form->{$_} } qw(action header exchangerate);
 
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
@@ -1399,11 +1481,15 @@ sub backorder_exchangerate {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_exchangerate {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->isblank("exchangerate", $locale->text('Exchangerate missing!'));
   $form->{exchangerate} =
@@ -1414,20 +1500,26 @@ sub save_exchangerate {
 
   &invoice;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_backorder {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->{shipped} = 1;
 
   # figure out if we need to create a backorder
   # items aren't saved if qty != 0
 
-  for $i (1 .. $form->{rowcount}) {
-    $totalqty  += $qty  = $form->{"qty_$i"};
-    $totalship += $ship = $form->{"ship_$i"};
+  my ($totalqty, $totalship);
+  for my $i (1 .. $form->{rowcount}) {
+    my $qty  = $form->{"qty_$i"};
+    my $ship = $form->{"ship_$i"};
+    $totalqty  += $qty;
+    $totalship += $ship;
 
     $form->{"qty_$i"} = $qty - $ship;
   }
@@ -1445,11 +1537,11 @@ sub create_backorder {
     return;
   }
 
-  @flds = (
+  my @flds = (
     qw(partnumber description qty ship unit sellprice discount id inventory_accno bin income_accno expense_accno listprice assembly taxaccounts partsgroup)
   );
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map {
       $form->{"${_}_$i"} =
         $form->format_amount(\%myconfig, $form->{"${_}_$i"})
@@ -1461,15 +1553,15 @@ sub create_backorder {
   OE->save(\%myconfig, \%$form);
 
   # rebuild rows for invoice
-  @a     = ();
-  $count = 0;
+  my @a     = ();
+  my $count = 0;
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     $form->{"qty_$i"} = $form->{"ship_$i"};
 
     if ($form->{"qty_$i"}) {
       push @a, {};
-      $j = $#a;
+      my $j = $#a;
       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
       $count++;
     }
@@ -1478,11 +1570,13 @@ sub create_backorder {
   $form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
   $form->{rowcount} = $count;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -1512,11 +1606,13 @@ sub save_as_new {
 
   &save;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_for_direct_delivery_yes {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -1525,11 +1621,13 @@ sub check_for_direct_delivery_yes {
   map { s/^CFDD_//; $form->{$_} = $form->{"CFDD_${_}"} } grep /^CFDD_/, keys %{ $form };
   $form->{shipto} = 1;
   purchase_order();
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_for_direct_delivery_no {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -1537,17 +1635,20 @@ sub check_for_direct_delivery_no {
   delete @{$form}{grep /^shipto/, keys %{ $form }};
   purchase_order();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub check_for_direct_delivery {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   check_oe_access();
 
   if ($form->{direct_delivery_checked}
       || (!$form->{shiptoname} && !$form->{shiptostreet} && !$form->{shipto_id})) {
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -1564,16 +1665,19 @@ sub check_for_direct_delivery {
   $form->header();
   print $form->parse_html_template("oe/check_for_direct_delivery");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   exit 0;
 }
 
 sub purchase_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   check_oe_access();
-  $auth->assert('purchase_order_edit');
+  $main::auth->assert('purchase_order_edit');
 
   if ($form->{type} eq 'sales_order') {
     check_for_direct_delivery();
@@ -1593,14 +1697,17 @@ sub purchase_order {
 
   &poso;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub sales_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   check_oe_access();
-  $auth->assert('sales_order_edit');
+  $main::auth->assert('sales_order_edit');
 
   if ($form->{type} eq "purchase_order") {
     delete($form->{ordnumber});
@@ -1616,14 +1723,17 @@ sub sales_order {
 
   &poso;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub poso {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   check_oe_access();
-  $auth->assert('purchase_order_edit | sales_order_edit');
+  $main::auth->assert('purchase_order_edit | sales_order_edit');
 
   $form->{transdate} = $form->current_date(\%myconfig);
   delete $form->{duedate};
@@ -1638,7 +1748,7 @@ sub poso {
   map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered
                                 ordnumber);
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor discount);
   }
 
@@ -1652,31 +1762,34 @@ sub poso {
 
   # prepare_order assumes that the discount is in db-notation (0.05) and not user-notation (5)
   # and therefore multiplies the values by 100 in the case of reading from db or making an order from several quotation, so we convert this back into percent-notation for the user interface by multiplying with 0.01
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * 0.01);
   };
 
   # format amounts
-  for $i (1 .. $form->{rowcount} - 1) {
+  for my $i (1 .. $form->{rowcount} - 1) {
     map { $form->{"${_}_$i"} =~ s/\"/&quot;/g } qw(partnumber description unit);
   }
 
   &update;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delivery_order {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   if ($form->{type} =~ /^sales/) {
-    $auth->assert('sales_delivery_order_edit');
+    $main::auth->assert('sales_delivery_order_edit');
 
     $form->{vc}    = 'customer';
     $form->{type}  = 'sales_delivery_order';
 
   } else {
-    $auth->assert('purchase_delivery_order_edit');
+    $main::auth->assert('purchase_delivery_order_edit');
 
     $form->{vc}    = 'vendor';
     $form->{type}  = 'purchase_delivery_order';
@@ -1698,7 +1811,7 @@ sub delivery_order {
   # reset
   delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)};
 
-  for $i (1 .. $form->{rowcount}) {
+  for my $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor discount);
   }
 
@@ -1712,11 +1825,13 @@ sub delivery_order {
 
   update();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub e_mail {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   check_oe_access();
 
@@ -1732,22 +1847,25 @@ sub e_mail {
 
   edit_e_mail();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub yes {
-  call_sub($form->{yes_nextsub});
+  call_sub($main::form->{yes_nextsub});
 }
 
 sub no {
-  call_sub($form->{no_nextsub});
+  call_sub($main::form->{no_nextsub});
 }
 
 ######################################################################################################
 # IO ENTKOPPLUNG
 # ###############################################################################################
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   check_oe_access();
 
@@ -1769,7 +1887,7 @@ sub display_form {
 
   $form->language_payment(\%myconfig);
 
-  Common::webdav_folder($form) if ($webdav);
+  Common::webdav_folder($form) if ($main::webdav);
 
   &form_header;
 
@@ -1778,11 +1896,13 @@ sub display_form {
 
   &form_footer;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_for_todo_list {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $quotations = OE->transactions_for_todo_list();
   my $content;
@@ -1794,7 +1914,7 @@ sub report_for_todo_list {
                                                                            'edit_url'   => $edit_url });
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $content;
 }
index 8c6132e..4d06f52 100644 (file)
@@ -35,14 +35,18 @@ use SL::PE;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 1;
 
 # end of main
 
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
 
   $form->{title} = "Add";
 
@@ -54,13 +58,16 @@ sub add {
   call_sub("form_$form->{type}_header");
   call_sub("form_$form->{type}_footer");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  $main::auth->assert('config');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
@@ -76,14 +83,18 @@ sub edit {
   call_sub("form_$form->{type}_header");
   call_sub("form_$form->{type}_footer");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
+  my ($report, $sort, $number);
   if ($form->{type} eq 'partsgroup') {
     $report        = "partsgroup_report";
     $sort          = 'partsgroup';
@@ -158,13 +169,17 @@ sub search {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  $main::auth->assert('config');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if ($form->{type} eq 'partsgroup') {
     $form->isblank("partsgroup", $locale->text('Group missing!'));
@@ -184,15 +199,19 @@ sub save {
        $form->{addition} = "SAVED";
        $form->save_history($form->dbconnect(\%myconfig));
   }
-  # /saving the history 
+  # /saving the history
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  $main::auth->assert('config');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   PE->delete_tuple(\%myconfig, \%$form);
 
@@ -209,22 +228,27 @@ sub delete {
        $form->save_history($form->dbconnect(\%myconfig));
   }
   # /saving the history
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
-sub continue { call_sub($form->{"nextsub"}); }
+sub continue { call_sub($main::form->{"nextsub"}); }
 
 sub partsgroup_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
+  map { $form->{$_} = $form->unescape($form->{$_}) } qw(partsgroup);
   PE->partsgroups(\%myconfig, \%$form);
 
-  $callback =
+  my $callback =
     "$form->{script}?action=partsgroup_report&type=$form->{type}&status=$form->{status}";
 
+  my ($option);
   if ($form->{status} eq 'all') {
     $option = $locale->text('All');
   }
@@ -236,8 +260,8 @@ sub partsgroup_report {
     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
   }
 
-  @column_index = $form->sort_columns(qw(partsgroup));
-
+  my @column_index = $form->sort_columns(qw(partsgroup));
+  my %column_header;
   $column_header{partsgroup} =
     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
 
@@ -274,7 +298,8 @@ sub partsgroup_report {
   # escape callback for href
   $callback = $form->escape($callback);
 
-  foreach $ref (@{ $form->{item_list} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{item_list} }) {
 
     $i++;
     $i %= 2;
@@ -317,13 +342,16 @@ sub partsgroup_report {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_partsgroup_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text("$form->{title} Group");
 
@@ -364,13 +392,16 @@ sub form_partsgroup_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub form_partsgroup_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('config');
+  $main::auth->assert('config');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   print qq|
 
@@ -389,9 +420,9 @@ sub form_partsgroup_footer {
 # button for saving history
 print qq|
        <input type=button onclick=set_history_window(|
-       . $form->{id} 
+       . $form->{id}
        . qq|); name=history id=history value=|
-       . $locale->text('history') 
+       . $locale->text('history')
        . qq|>|;
 # /button for saving history
   print qq|
@@ -401,23 +432,28 @@ print qq|
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 #################################
 # get pricesgroups and build up html-code
 #
 sub pricegroup_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup);
+  map { $form->{$_} = $form->unescape($form->{$_}) } qw(pricegroup);
   PE->pricegroups(\%myconfig, \%$form);
 
-  $callback =
+  my $callback =
     "$form->{script}?action=pricegroup_report&type=$form->{type}&status=$form->{status}";
 
+  my $option;
   if ($form->{status} eq 'all') {
     $option = $locale->text('All');
   }
@@ -430,8 +466,8 @@ sub pricegroup_report {
       "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
   }
 
-  @column_index = $form->sort_columns(qw(pricegroup));
-
+  my @column_index = $form->sort_columns(qw(pricegroup));
+  my %column_header;
   $column_header{pricegroup} =
       qq|<th class=listheading width=90%>|
     . $locale->text('Pricegroup')
@@ -470,7 +506,8 @@ sub pricegroup_report {
   # escape callback for href
   $callback = $form->escape($callback);
 
-  foreach $ref (@{ $form->{item_list} }) {
+  my ($i, %column_data);
+  foreach my $ref (@{ $form->{item_list} }) {
 
     $i++;
     $i %= 2;
@@ -513,16 +550,19 @@ sub pricegroup_report {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 #######################
 #build up pricegroup_header
 #
 sub form_pricegroup_header {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   # $locale->text('Add Pricegroup')
   # $locale->text('Edit Pricegroup')
@@ -562,15 +602,18 @@ sub form_pricegroup_header {
 </table>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 ######################
 #build up pricegroup_footer
 #
 sub form_pricegroup_footer {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('config');
 
-  $auth->assert('config');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   print qq|
 
@@ -589,9 +632,9 @@ sub form_pricegroup_footer {
 # button for saving history
 print qq|
        <input type=button onclick=set_history_window(|
-       . $form->{id} 
+       . $form->{id}
        . qq|); name=history id=history value=|
-       . $locale->text('history') 
+       . $locale->text('history')
        . qq|>|;
 # /button for saving history
   print qq|
@@ -601,5 +644,5 @@ print qq|
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
index a9740b1..d340ddb 100644 (file)
@@ -39,23 +39,31 @@ use SL::ReportGenerator;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   # construct callback
   $form->{callback} = build_std_url('action') unless $form->{callback};
 
   display_project_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
@@ -66,13 +74,16 @@ sub edit {
 
   display_project_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('project_edit');
+  $main::auth->assert('project_edit');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Projects');
 
@@ -85,13 +96,17 @@ sub search {
   $form->header();
   print $form->parse_html_template('projects/search');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub project_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{sort} ||= 'projectnumber';
   my $filter      = $form->{filter} || { };
@@ -163,7 +178,7 @@ sub project_report {
   my $edit_url = build_std_url('action=edit&type=project');
   my $callback = $form->escape($href) . '&sort=' . E($form->{sort});
 
-  foreach $project (@{ $form->{project_list} }) {
+  foreach my $project (@{ $form->{project_list} }) {
     $project->{active} = $project->{active} ? $locale->text('Yes')  : $locale->text('No');
 
     my $row = { map { $_ => { 'data' => $project->{$_} } } keys %{ $project } };
@@ -175,13 +190,16 @@ sub project_report {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_project_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('project_edit');
+  $main::auth->assert('project_edit');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{project} ||= { };
 
@@ -194,13 +212,17 @@ sub display_project_form {
   $form->header();
   print $form->parse_html_template('projects/project_form');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->isblank("project.projectnumber", $locale->text('Project Number missing!'));
 
@@ -225,22 +247,29 @@ sub save {
 
   $form->redirect($locale->text('Project saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   delete $form->{project}->{id} if ($form->{project});
   save();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my $project = $form->{project} || { };
   Projects->delete_project('id' => $project->{id});
@@ -255,9 +284,9 @@ sub delete {
 
   $form->redirect($locale->text('Project deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub continue {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }
index 4734433..df360ad 100644 (file)
@@ -35,18 +35,24 @@ use SL::RC;
 
 require "bin/mozilla/common.pl";
 
+use strict;
+
 1;
 
 # end of main
 
 sub reconciliation {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('cash');
+  $main::auth->assert('cash');
 
   RC->paymentaccounts(\%myconfig, \%$form);
 
-  $selection = "";
+  my $selection = "";
   map { $selection .= "<option>$_->{accno}--$_->{description}\n" }
     @{ $form->{PR} };
 
@@ -54,7 +60,7 @@ sub reconciliation {
   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
   $form->{"jsscript"} = 1;
   $form->header;
-  $onload = qq|focus()|;
+  my $onload = qq|focus()|;
   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
 
   print qq|
@@ -107,15 +113,18 @@ sub reconciliation {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
-sub continue { call_sub($form->{"nextsub"}); }
+sub continue { call_sub($main::form->{"nextsub"}); }
 
 sub get_payments {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('cash');
+  $main::auth->assert('cash');
 
   ($form->{accno}, $form->{account}) = split /--/, $form->{accno};
 
@@ -123,16 +132,20 @@ sub get_payments {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('cash');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  @column_index = qw(cleared transdate source name credit debit balance);
+  $main::auth->assert('cash');
 
+  my @column_index = qw(cleared transdate source name credit debit balance);
+  my %column_header;
   $column_header{cleared} = "<th>&nbsp;</th>";
   $column_header{source}  =
     "<th class=listheading>" . $locale->text('Source') . "</a></th>";
@@ -156,6 +169,7 @@ sub display_form {
   $column_header{balance} =
     "<th class=listheading>" . $locale->text('Balance') . "</a></th>";
 
+  my $option;
   if ($form->{fromdate}) {
     $option .= "\n<br>" if ($option);
     $option .=
@@ -198,18 +212,20 @@ sub display_form {
         </tr>
 |;
 
-  $ml = ($form->{category} eq 'A') ? -1 : 1;
+  my $ml = ($form->{category} eq 'A') ? -1 : 1;
   $form->{beginningbalance} *= $ml;
-  $clearedbalance = $balance = $form->{beginningbalance};
-  $i              = 0;
-  $id             = 0;
+  my $balance        = $form->{beginningbalance};
+  my $clearedbalance = $balance;
+  my $i              = 0;
+  my $id             = 0;
 
+  my %column_data;
   map { $column_data{$_} = "<td>&nbsp;</td>" }
     qw(cleared transdate source name debit credit);
   $column_data{balance} =
     "<td align=right>"
     . $form->format_amount(\%myconfig, $balance, 2, 0) . "</td>";
-  $j = 0;
+  my $j = 0;
   print qq|
        <tr class=listrow$j>
 |;
@@ -220,7 +236,12 @@ sub display_form {
        </tr>
 |;
 
-  foreach $ref (@{ $form->{PR} }) {
+  my $cleared;
+  my $totaldebits;
+  my $totalcredits;
+  my $fx_transaction;
+  my $fx;
+  foreach my $ref (@{ $form->{PR} }) {
 
     $balance += $ref->{amount} * $ml;
     $cleared += $ref->{amount} * $ml if $ref->{cleared};
@@ -300,7 +321,7 @@ sub display_form {
 
   $form->{statementbalance} =
     $form->parse_amount(\%myconfig, $form->{statementbalance});
-  $difference =
+  my $difference =
     $form->format_amount(\%myconfig,
                         $form->{statementbalance} - $clearedbalance - $cleared,
                         2, 0);
@@ -310,6 +331,7 @@ sub display_form {
 
   $clearedbalance = $form->format_amount(\%myconfig, $clearedbalance, 2, 0);
 
+  my $exchdiff;
   if ($fx) {
     $fx       = $form->format_amount(\%myconfig, $fx, 2, 0);
     $exchdiff = qq|
@@ -386,17 +408,21 @@ sub display_form {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub update {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('cash');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+
+  $main::auth->assert('cash');
 
   RC->payment_transactions(\%myconfig, \%$form);
 
-  foreach $ref (@{ $form->{PR} }) {
+  my $i;
+  foreach my $ref (@{ $form->{PR} }) {
     if (!$ref->{fx_transaction}) {
       $i++;
       $ref->{cleared} = ($form->{"cleared_$i"}) ? "checked" : "";
@@ -405,13 +431,16 @@ sub update {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub select_all {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
-  $auth->assert('cash');
+  $main::auth->assert('cash');
 
   RC->payment_transactions(\%myconfig, \%$form);
 
@@ -420,13 +449,17 @@ sub select_all {
 
   &display_form;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub done {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  $auth->assert('cash');
+  $main::auth->assert('cash');
 
   $form->{callback} = "$form->{script}?action=reconciliation";
 
@@ -435,6 +468,6 @@ sub done {
   RC->reconcile(\%myconfig, \%$form);
   $form->redirect;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
index 5f5d407..89f3b72 100644 (file)
@@ -16,8 +16,12 @@ use SL::Common;
 use SL::MoreCommon;
 use SL::ReportGenerator;
 
+use strict;
+
 sub report_generator_set_default_sort {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my $default_sortorder   = shift;
   my $default_sortdir     = shift;
@@ -26,12 +30,16 @@ sub report_generator_set_default_sort {
   $form->{sortdir}        = $default_sortdir unless (defined $form->{sortdir});
   $form->{sortdir}        = $form->{sortdir} ? 1 : 0;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub report_generator_export_as_pdf {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if ($form->{report_generator_pdf_options_set}) {
     my $saved_form = save_form();
@@ -44,7 +52,7 @@ sub report_generator_export_as_pdf {
       report_generator_do('HTML');
     }
 
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -64,15 +72,18 @@ sub report_generator_export_as_pdf {
   print $form->parse_html_template('report_generator/pdf_export_options', { 'HIDDEN'               => \@form_values,
                                                                             'ALLOW_FONT_SELECTION' => $allow_font_selection, });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_generator_export_as_csv {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   if ($form->{report_generator_csv_options_set}) {
     report_generator_do('CSV');
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return;
   }
 
@@ -82,22 +93,25 @@ sub report_generator_export_as_csv {
   $form->header();
   print $form->parse_html_template('report_generator/csv_export_options', { 'HIDDEN' => \@form_values });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_generator_back {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   report_generator_do('HTML');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_generator_do {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $format  = shift;
 
+  my $form     = $main::form;
+  my $locale   = $main::locale;
+
   my $nextsub = $form->{report_generator_nextsub};
   if (!$nextsub) {
     $form->error($locale->text('report_generator_nextsub is not defined.'));
@@ -113,11 +127,14 @@ sub report_generator_do {
 
   call_sub($nextsub);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub report_generator_dispatcher {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   my $nextsub = $form->{report_generator_dispatch_to};
   if (!$nextsub) {
@@ -128,7 +145,7 @@ sub report_generator_dispatcher {
 
   call_sub($nextsub);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 1;
index 41148c8..5115ddd 100644 (file)
@@ -47,9 +47,10 @@ require "bin/mozilla/arap.pl";
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 
-1;
-
-# end of main
+# note: this file was particularly hard to strictify.
+# alot of the vars are passed carelessly between invocations
+# should there be any missing vars, declare them globally
+use strict;
 
 # this is for our long dates
 # $locale->text('January')
@@ -106,19 +107,30 @@ my $rp_access_map = {
   'balance_sheet'    => 'report',
 };
 
+# subs use these pretty freely, so declare them here
+our (%column_data, @column_index);
+our ($subtotalnetamount, $subtotaltax, $subtotal);
+
 sub check_rp_access {
+  my $form     = $main::form;
+
   my $right   = $rp_access_map->{$form->{report}};
   $right    ||= 'DOES_NOT_EXIST';
 
-  $auth->assert($right);
+  $main::auth->assert($right);
 }
 
 sub report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   check_rp_access();
 
-  %title = ('balance_sheet'        => 'Balance Sheet',
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
+  my %title = (
+            'balance_sheet'        => 'Balance Sheet',
             'income_statement'     => 'Income Statement',
             'trial_balance'        => 'Trial Balance',
             'ar_aging'             => 'AR Aging',
@@ -130,14 +142,15 @@ sub report {
             'receipts'             => 'Receipts',
             'payments'             => 'Payments',
             'projects'             => 'Project Transactions',
-            'bwa'                  => 'Betriebswirtschaftliche Auswertung',);
+            'bwa'                  => 'Betriebswirtschaftliche Auswertung',
+  );
 
   $form->{title} = $locale->text($title{ $form->{report} });
 
-  $accrual = ($eur) ? ""        : "checked";
-  $cash    = ($eur) ? "checked" : "";
+  my $accrual = ($main::eur) ? ""        : "checked";
+  my $cash    = ($main::eur) ? "checked" : "";
 
-  $year = (localtime)[5] + 1900;
+  my $year = (localtime)[5] + 1900;
 
   # get departments
   $form->all_departments(\%myconfig);
@@ -146,7 +159,7 @@ sub report {
     map { $form->{selectdepartment} .= "<option>$_->{description}--$_->{id}\n" } @{ $form->{all_departments} };
   }
 
-  $department = qq|
+  my $department = qq|
        <tr>
          <th align=right nowrap>| . $locale->text('Department') . qq|</th>
          <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
@@ -164,13 +177,14 @@ sub report {
   }
 
   my $projectnumber =
-    NTI($cgi->popup_menu('-name' => "project_id",
-                         '-values' => \@project_values,
-                         '-labels' => \%project_labels));
+    NTI($main::cgi->popup_menu('-name' => "project_id",
+                               '-values' => \@project_values,
+                               '-labels' => \%project_labels));
 
   # use JavaScript Calendar or not
   $form->{jsscript} = 1;
-  $jsscript = "";
+  my $jsscript = "";
+  my ( $name_1, $id_1, $value_1, $trigger_1, $name_2, $id_2, $value_2, $trigger_2, );
   if ($form->{report} eq "balance_sheet") {
     $name_1    = "asofdate";
     $id_1      = "asofdate";
@@ -210,6 +224,9 @@ sub report {
     $trigger_2 = "trigger2";
   }
 
+  my ($button1, $button1_2, $button2, $button2_2);
+  my $checked;
+
   # with JavaScript Calendar
   if ($form->{jsscript}) {
     if ($name_1 eq "") {
@@ -239,7 +256,7 @@ sub report {
   }
   $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
   $form->header;
-  $onload = qq|focus()|;
+  my $onload = qq|focus()|;
   $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
   $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
   print qq|
@@ -626,7 +643,7 @@ $jsscript
 |;
 
     $checked = "checked";
-    foreach $ref (@{ $form->{taxaccounts} }) {
+    foreach my $ref (@{ $form->{taxaccounts} }) {
 
       print
         qq|<input name=accno class=radio type=radio value=$ref->{accno} $checked>&nbsp;$ref->{description}
@@ -760,6 +777,7 @@ $jsscript
 
   }
 
+  my ($label, $nextsub, $vc);
   if (($form->{report} eq "ar_aging") || ($form->{report} eq "ap_aging")) {
     if ($form->{report} eq 'ar_aging') {
       $label = $locale->text('Customer');
@@ -810,13 +828,14 @@ $jsscript
 
   # above action can be removed if there is more than one input field
 
+  my ($selection, $paymentaccounts);
   if ($form->{report} =~ /(receipts|payments)$/) {
     $form->{db} = ($form->{report} =~ /payments$/) ? "ap" : "ar";
 
     RP->paymentaccounts(\%myconfig, \%$form);
 
     $selection = "<option>\n";
-    foreach $ref (@{ $form->{PR} }) {
+    foreach my $ref (@{ $form->{PR} }) {
       $paymentaccounts .= "$ref->{accno} ";
       $selection       .= "<option>$ref->{accno}--$ref->{description}\n";
     }
@@ -887,15 +906,19 @@ $jsscript
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
-sub continue { call_sub($form->{"nextsub"}); }
+sub continue { call_sub($main::form->{"nextsub"}); }
 
 sub get_project {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('report');
+  $main::auth->assert('report');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my $nextsub = shift;
 
@@ -914,13 +937,17 @@ sub get_project {
     $form->{project_id} = $form->{project_id_1};
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_income_statement {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('report');
 
-  $auth->assert('report');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{padding} = "&nbsp;&nbsp;";
   $form->{bold}    = "<b>";
@@ -971,7 +998,7 @@ sub generate_income_statement {
         $form->{fromdate} = "1.2.$form->{year}";
 
         #this works from 1901 to 2099, 1900 and 2100 fail.
-        $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
         $form->{todate} = "$leap.2.$form->{year}";
         last SWITCH;
       };
@@ -1043,11 +1070,11 @@ sub generate_income_statement {
       $form->{todate} = $form->current_date(\%myconfig);
     }
 
-    $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
-    $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
+    my $longtodate  = $locale->date(\%myconfig, $form->{todate}, 1);
+    my $shorttodate = $locale->date(\%myconfig, $form->{todate}, 0);
 
-    $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
-    $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
+    my $longfromdate  = $locale->date(\%myconfig, $form->{fromdate}, 1);
+    my $shortfromdate = $locale->date(\%myconfig, $form->{fromdate}, 0);
 
     $form->{this_period} = "$shortfromdate\n$shorttodate";
     $form->{period}      =
@@ -1058,13 +1085,11 @@ sub generate_income_statement {
   }
 
   if ($form->{comparefromdate} || $form->{comparetodate}) {
-    $longcomparefromdate =
-      $locale->date(\%myconfig, $form->{comparefromdate}, 1);
-    $shortcomparefromdate =
-      $locale->date(\%myconfig, $form->{comparefromdate}, 0);
+    my $longcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 1);
+    my $shortcomparefromdate = $locale->date(\%myconfig, $form->{comparefromdate}, 0);
 
-    $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
-    $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
+    my $longcomparetodate  = $locale->date(\%myconfig, $form->{comparetodate}, 1);
+    my $shortcomparetodate = $locale->date(\%myconfig, $form->{comparetodate}, 0);
 
     $form->{last_period} = "$shortcomparefromdate\n$shortcomparetodate";
     $form->{period} .=
@@ -1074,7 +1099,7 @@ sub generate_income_statement {
   }
 
   # setup variables for the form
-  @a = qw(company address businessnumber);
+  my @a = qw(company address businessnumber);
   map { $form->{$_} = $myconfig{$_} } @a;
 
   $form->{templates} = $myconfig{templates};
@@ -1083,13 +1108,17 @@ sub generate_income_statement {
 
   $form->parse_template;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_balance_sheet {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('report');
+  $main::auth->assert('report');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{decimalplaces} = $form->{decimalplaces} * 1 || 2;
   $form->{padding} = "&nbsp;&nbsp;";
@@ -1105,7 +1134,7 @@ sub generate_balance_sheet {
   ($form->{department}) = split /--/, $form->{department};
 
   # define Current Earnings account
-  $padding = ($form->{l_heading}) ? $form->{padding} : "";
+  my $padding = ($form->{l_heading}) ? $form->{padding} : "";
   push(@{ $form->{equity_account} }, $padding . $locale->text('Current Earnings'));
 
   $form->{this_period} = $locale->date(\%myconfig, $form->{asofdate}, 0);
@@ -1122,15 +1151,19 @@ sub generate_balance_sheet {
   print $form->parse_html_template('rp/balance_sheet', $data);
 #  $form->parse_template();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_projects {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('report');
 
-  $auth->assert('report');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
-  &get_project(generate_projects);
+  &get_project("generate_projects");
   $form->{projectnumber} = $form->{projectnumber_1};
 
   $form->{nextsub} = "generate_projects";
@@ -1139,7 +1172,7 @@ sub generate_projects {
 
   list_accounts('generate_projects');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # Antonio Gallardo
@@ -1149,9 +1182,13 @@ sub generate_projects {
 # added headers and subtotals
 #
 sub generate_trial_balance {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('report');
+  $main::auth->assert('report');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if ($form->{reporttype} eq "custom") {
 
@@ -1197,7 +1234,7 @@ sub generate_trial_balance {
         $form->{fromdate} = "1.2.$form->{year}";
 
         #this works from 1901 to 2099, 1900 and 2100 fail.
-        $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
         $form->{todate} = "$leap.2.$form->{year}";
         last SWITCH;
       };
@@ -1259,7 +1296,7 @@ sub generate_trial_balance {
   RP->trial_balance(\%myconfig, \%$form, 'beginning_balances' => 1);
 
 
-  $form->{rowcount} = scalar @{ $form->{TB} };
+  $form->{rowcount} = scalar @{ $form->{TB} || [] };
   $form->{title} = sprintf($locale->text('Trial balance between %s and %s'), $form->{fromdate}, $form->{todate});
 
   my @columns = (
@@ -1331,7 +1368,7 @@ sub generate_trial_balance {
   $form->{callback} = $href .= "&sort=$form->{sort}";
 
   # escape callback for href
-  $callback = $form->escape($href);
+  my $callback = $form->escape($href);
 
   my @subtotal_columns = qw(soll_eb haben_eb soll haben soll_kumuliert haben_kumuliert soll_saldo haben_saldo);
 
@@ -1339,7 +1376,8 @@ sub generate_trial_balance {
 
   my $edit_url = build_std_url('action=edit', 'type', 'vc');
 
-  foreach $accno (@{ $form->{TB} }) {
+  my $idx;
+  foreach my $accno (@{ $form->{TB} }) {
 
     $accno->{soll} = $accno->{debit};
     $accno->{haben} = $accno->{credit};
@@ -1357,8 +1395,6 @@ sub generate_trial_balance {
       };
     }
 
-
-    $row->{$ordnumber}->{link} = $edit_url . "&id=" . E($oe->{id}) . "&callback=${callback}";
     $row->{accno}->{link} = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($accno->{accno}), 'description=' . E($accno->{description}), 'fromdate=' . E($form->{fromdate}), 'todate=' . E($form->{todate}), 'method=' . E($form->{method}));
 
     my $row_set = [ $row ];
@@ -1375,15 +1411,19 @@ sub generate_trial_balance {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
 }
 
 sub create_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
@@ -1392,30 +1432,38 @@ sub create_subtotal_row {
 
   map { $totals->{$_} = 0 } @{ $subtotal_columns };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub create_list_accounts_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($subtotals, $columns, $fields, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
   map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $subtotals->{$_}, 2) } @{ $fields };
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub list_accounts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($action) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my @options;
   if ($form->{department}) {
     my ($department) = split /--/, $form->{department};
@@ -1528,13 +1576,17 @@ sub list_accounts {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_ar_aging {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # split customer
   ($form->{customer}) = split(/--/, $form->{customer});
@@ -1547,13 +1599,17 @@ sub generate_ar_aging {
   RP->aging(\%myconfig, \%$form);
   aging();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_ap_aging {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # split vendor
   ($form->{vendor}) = split(/--/, $form->{vendor});
@@ -1566,14 +1622,18 @@ sub generate_ap_aging {
   RP->aging(\%myconfig, \%$form);
   aging();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub create_aging_subtotal_row {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($subtotals, $columns, $periods, $class) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
 
   foreach (@{ $periods }) {
@@ -1581,15 +1641,20 @@ sub create_aging_subtotal_row {
     $subtotals->{$_}      = 0;
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $row;
 }
 
 sub aging {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+  my $cgi      = $main::cgi;
 
   my $report = SL::ReportGenerator->new(\%myconfig, $form);
 
@@ -1642,7 +1707,7 @@ sub aging {
     push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
   }
 
-  my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
+  $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
 
   $report->set_options('top_info_text'        => join("\n", @options),
                        'output_format'        => 'HTML',
@@ -1656,7 +1721,7 @@ sub aging {
   my %subtotals     = map { $_ => 0 } @periods;
   my %totals        = map { $_ => 0 } @periods;
 
-  foreach $ref (@{ $form->{AG} }) {
+  foreach my $ref (@{ $form->{AG} }) {
     if ($row_idx && ($previous_ctid != $ref->{ctid})) {
       $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
     }
@@ -1698,8 +1763,8 @@ sub aging {
   $report->add_data(create_aging_subtotal_row(\%totals, \@columns, \@periods, 'listtotal'));
 
   if ($form->{arap} eq 'ar') {
-    $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
-    $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
+    my $raw_top_info_text    = $form->parse_html_template('rp/aging_ar_top');
+    my $raw_bottom_info_text = $form->parse_html_template('rp/aging_ar_bottom', { 'row_idx' => $row_idx,
                                                                                'PRINT_OPTIONS' => print_options(inline => 1), });
     $report->set_options('raw_top_info_text'    => $raw_top_info_text,
                          'raw_bottom_info_text' => $raw_bottom_info_text);
@@ -1709,11 +1774,15 @@ sub aging {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub select_all {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   RP->aging(\%myconfig, \%$form);
 
@@ -1721,16 +1790,21 @@ sub select_all {
 
   &aging;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub e_mail {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   # get name and email addresses
-  for $i (1 .. $form->{rowcount}) {
+  my $selected = 0;
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->{"statement_$i"}) {
       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
       RP->get_customer(\%myconfig, \%$form);
@@ -1741,6 +1815,7 @@ sub e_mail {
 
   $form->error($locale->text('Nothing selected!')) unless $selected;
 
+  my $bcc = '';
   if ($myconfig{role} eq 'admin') {
     $bcc = qq|
           <th align=right nowrap=true>| . $locale->text('Bcc') . qq|</th>
@@ -1748,7 +1823,7 @@ sub e_mail {
 |;
   }
 
-  $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
+  my $title = $locale->text('E-mail Statement to') . " $form->{$form->{ct}}";
 
   $form->{media} = "email";
 
@@ -1803,7 +1878,7 @@ sub e_mail {
     qw(action email cc bcc subject message type sendmode format header);
 
   # save all other variables
-  foreach $key (keys %$form) {
+  foreach my $key (keys %$form) {
     next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
     $form->{$key} =~ s/\"/&quot;/g;
     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
@@ -1828,13 +1903,17 @@ sub e_mail {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub send_email {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{subject} = $locale->text('Statement') . qq| - $form->{todate}|
     unless $form->{subject};
@@ -1848,20 +1927,25 @@ sub send_email {
 
   $form->redirect($locale->text('Statement sent to') . " $form->{$form->{ct}}");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if ($form->{media} eq 'printer') {
     $form->error($locale->text('Select postscript or PDF!'))
       if ($form->{format} !~ /(postscript|pdf)/);
   }
 
-  for $i (1 .. $form->{rowcount}) {
+  my $selected = 0;
+  for my $i (1 .. $form->{rowcount}) {
     if ($form->{"statement_$i"}) {
       $form->{"$form->{ct}_id"} = $form->{"$form->{ct}_id_$i"};
       $selected = 1;
@@ -1884,13 +1968,17 @@ sub print {
   $form->redirect($locale->text('Statements sent to printer!'))
     if ($form->{media} eq 'printer');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('general_ledger');
+  $main::auth->assert('general_ledger');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
 
@@ -1914,10 +2002,11 @@ sub print_form {
   # Save $form->{email} because it will be overwritten.
   $form->{EMAIL_RECIPIENT} = $form->{email};
 
-  $i = 0;
+  my $i = 0;
+  my $ctid;
   while (@{ $form->{AG} }) {
 
-    $ref = shift @{ $form->{AG} };
+    my $ref = shift @{ $form->{AG} };
 
     if ($ctid != $ref->{ctid}) {
 
@@ -1926,8 +2015,8 @@ sub print_form {
 
       if ($form->{"statement_$i"}) {
 
-        @a =
-          (name, street, zipcode, city, country, contact, email,
+        my @a =
+          ("name", "street", "zipcode", "city", "country", "contact", "email",
            "$form->{ct}phone", "$form->{ct}fax");
         map { $form->{$_} = $ref->{$_} } @a;
 
@@ -1936,7 +2025,7 @@ sub print_form {
 
         map { $form->{$_} = () } qw(invnumber invdate duedate);
         $form->{total} = 0;
-        foreach $item (qw(c0 c30 c60 c90)) {
+        foreach my $item (qw(c0 c30 c60 c90)) {
           $form->{$item} = ();
           $form->{"${item}total"} = 0;
         }
@@ -1968,12 +2057,12 @@ sub print_form {
         map {
           $form->{"${_}total"} =
             $form->format_amount(\%myconfig, $form->{"${_}total"}, 2)
-        } (c0, c30, c60, c90, "");
+        } ('c0', 'c30', 'c60', 'c90', "");
 
         $form->{attachment_filename} =  $locale->quote_special_chars('filenames', $locale->text("Statement") . "_$form->{todate}.$attachment_suffix");
         $form->{attachment_filename} =~ s/\s+/_/g;
 
-        $form->parse_template(\%myconfig, $userspath);
+        $form->parse_template(\%myconfig, $main::userspath);
 
       }
     }
@@ -1986,13 +2075,17 @@ sub print_form {
        $form->save_history($form->dbconnect(\%myconfig));
   }
   # /saving the history
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub statement_details {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('general_ledger');
 
-  $auth->assert('general_ledger');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my ($ref) = @_;
 
@@ -2000,7 +2093,7 @@ sub statement_details {
   push @{ $form->{invdate} },   $ref->{transdate};
   push @{ $form->{duedate} },   $ref->{duedate};
 
-  foreach $item (qw(c0 c30 c60 c90)) {
+  foreach my $item (qw(c0 c30 c60 c90)) {
     if ($ref->{exchangerate} * 1) {
       $ref->{$item} =
         $form->round_amount($ref->{$item} / $ref->{exchangerate}, 2);
@@ -2011,43 +2104,48 @@ sub statement_details {
       $form->format_amount(\%myconfig, $ref->{$item}, 2);
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_tax_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('report');
+  $main::auth->assert('report');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   RP->tax_report(\%myconfig, \%$form);
 
-  $descvar     = "$form->{accno}_description";
-  $description = $form->escape($form->{$descvar});
-  $ratevar     = "$form->{accno}_rate";
+  my $descvar     = "$form->{accno}_description";
+  my $description = $form->escape($form->{$descvar});
+  my $ratevar     = "$form->{accno}_rate";
+  our $taxrate; # most likely error
 
-  $department = $form->escape($form->{department});
+  my $department = $form->escape($form->{department});
 
   # construct href
-  $href =
+  my $href =
     "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
   # construct callback
   $description = $form->escape($form->{$descvar},   1);
   $department  = $form->escape($form->{department}, 1);
-  $callback    =
+  my $callback    =
     "$form->{script}?&action=generate_tax_report&fromdate=$form->{fromdate}&todate=$form->{todate}&db=$form->{db}&method=$form->{method}&accno=$form->{accno}&$descvar=$description&department=$department&$ratevar=$taxrate&report=$form->{report}";
 
-  $title = $form->escape($form->{title});
+  my $title = $form->escape($form->{title});
   $href .= "&title=$title";
   $title = $form->escape($form->{title}, 1);
   $callback .= "&title=$title";
 
   $form->{title} = qq|$form->{title} $form->{"$form->{accno}_description"} |;
 
-  @columns =
+  my @columns =
     $form->sort_columns(qw(id transdate invnumber name netamount tax amount));
 
-  foreach $item (@columns) {
+  foreach my $item (@columns) {
     if ($form->{"l_$item"} eq "Y") {
       push @column_index, $item;
 
@@ -2062,11 +2160,13 @@ sub generate_tax_report {
     $href     .= "&l_subtotal=Y";
   }
 
+  my $option;
   if ($form->{department}) {
     ($department) = split /--/, $form->{department};
     $option = $locale->text('Department') . " : $department";
   }
 
+  my ($fromdate, $todate);
   # if there are any dates
   if ($form->{fromdate} || $form->{todate}) {
     if ($form->{fromdate}) {
@@ -2082,6 +2182,7 @@ sub generate_tax_report {
       $locale->date(\%myconfig, $form->current_date(\%myconfig), 1);
   }
 
+  my ($name, $invoice, $arap);
   if ($form->{db} eq 'ar') {
     $name    = $locale->text('Customer');
     $invoice = 'is.pl';
@@ -2096,6 +2197,7 @@ sub generate_tax_report {
   $option .= "<br>" if $option;
   $option .= "$form->{period}";
 
+  my %column_header;
   $column_header{id}        = qq|<th><a class=listheading href=$href&sort=id>| . $locale->text('ID') . qq|</th>|;
   $column_header{invnumber} = qq|<th><a class=listheading href=$href&sort=invnumber>| . $locale->text('Invoice') . qq|</th>|;
   $column_header{transdate} = qq|<th><a class=listheading href=$href&sort=transdate>| . $locale->text('Date') . qq|</th>|;
@@ -2112,7 +2214,7 @@ sub generate_tax_report {
 
 <table width=100%>
   <tr>
-    <th class=listtop colspan=$colspan>$form->{title}</th>
+    <th class=listtop>$form->{title}</th>
   </tr>
   <tr height="5"></tr>
   <tr>
@@ -2133,13 +2235,16 @@ sub generate_tax_report {
   # add sort and escape callback
   $callback = $form->escape($callback . "&sort=$form->{sort}");
 
+  my $sameitem;
   if (@{ $form->{TR} }) {
     $sameitem = $form->{TR}->[0]->{ $form->{sort} };
   }
 
-  foreach $ref (@{ $form->{TR} }) {
+  my ($totalnetamount, $totaltax);
+  my ($i);
+  foreach my $ref (@{ $form->{TR} }) {
 
-    $module = ($ref->{invoice}) ? $invoice : $arap;
+    my $module = ($ref->{invoice}) ? $invoice : $arap;
 
     if ($form->{l_subtotal} eq 'Y') {
       if ($sameitem ne $ref->{ $form->{sort} }) {
@@ -2193,14 +2298,11 @@ sub generate_tax_report {
        <tr class=listtotal>
 |;
 
-  $total =
-    $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
-  $totalnetamount =
-    $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
-  $totaltax = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
+  my $total          = $form->format_amount(\%myconfig, $totalnetamount + $totaltax, 2, "&nbsp;");
+  $totalnetamount = $form->format_amount(\%myconfig, $totalnetamount, 2, "&nbsp;");
+  $totaltax       = $form->format_amount(\%myconfig, $totaltax, 2, "&nbsp;");
 
-  $column_data{netamount} =
-    qq|<th class=listtotal align=right>$totalnetamount</th>|;
+  $column_data{netamount} = qq|<th class=listtotal align=right>$totalnetamount</th>|;
   $column_data{tax}    = qq|<th class=listtotal align=right>$totaltax</th>|;
   $column_data{amount} = qq|<th class=listtotal align=right>$total</th>|;
 
@@ -2220,25 +2322,25 @@ sub generate_tax_report {
 </html>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub tax_subtotal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
 
-  $subtotalnetamount =
-    $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
-  $subtotaltax = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
-  $subtotal =
-    $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax,
-                         2, "&nbsp;");
+  $subtotalnetamount = $form->format_amount(\%myconfig, $subtotalnetamount, 2, "&nbsp;");
+  $subtotaltax       = $form->format_amount(\%myconfig, $subtotaltax, 2, "&nbsp;");
+  $subtotal          = $form->format_amount(\%myconfig, $subtotalnetamount + $subtotaltax, 2, "&nbsp;");
 
-  $column_data{netamount} =
-    "<th class=listsubtotal align=right>$subtotalnetamount</th>";
-  $column_data{tax} = "<th class=listsubtotal align=right>$subtotaltax</th>";
-  $column_data{amount} = "<th class=listsubtotal align=right>$subtotal</th>";
+  $column_data{netamount} = "<th class=listsubtotal align=right>$subtotalnetamount</th>";
+  $column_data{tax}       = "<th class=listsubtotal align=right>$subtotaltax</th>";
+  $column_data{amount}    = "<th class=listsubtotal align=right>$subtotal</th>";
 
   $subtotalnetamount = 0;
   $subtotaltax       = 0;
@@ -2252,19 +2354,25 @@ sub tax_subtotal {
         </tr>
 |;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub list_payments {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('cash');
 
-  $auth->assert('cash');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   if ($form->{account}) {
     ($form->{paymentaccounts}) = split /--/, $form->{account};
   }
+
+  my $option;
   if ($form->{department}) {
-    ($department, $form->{department_id}) = split /--/, $form->{department};
+    (my $department, $form->{department_id}) = split /--/, $form->{department};
     $option = $locale->text('Department') . " : $department";
   }
 
@@ -2377,14 +2485,18 @@ sub list_payments {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub print_options {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my ($dont_print) = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $form->{sendmode} = "attachment";
 
   $form->{"format"} =
@@ -2402,7 +2514,8 @@ sub print_options {
   $form->{OP}{ $form->{media} }    = "selected";
   $form->{SM}{ $form->{sendmode} } = "selected";
 
-  $type = qq|
+  my ($media);
+  my $type = qq|
            <option value=statement $form->{PD}{statement}>|
       . $locale->text('Statement');
 
@@ -2414,14 +2527,15 @@ sub print_options {
   } else {
     $media = qq|
            <option value=screen $form->{OP}{screen}>| . $locale->text('Screen');
-    if ($myconfig{printer} && $latex_templates) {
+    if ($myconfig{printer} && $main::latex_templates) {
       $media .= qq|
             <option value=printer $form->{OP}{printer}>|
         . $locale->text('Printer');
     }
   }
 
-  if ($latex_templates) {
+  my $format;
+  if ($main::latex_templates) {
     $format .= qq|
             <option value=html $form->{DF}{html}>| . $locale->text('HTML')
       . qq| <option value=pdf $form->{DF}{pdf}>| . $locale->text('PDF')
@@ -2436,7 +2550,7 @@ sub print_options {
     <td><select name=media>$media</select></td>
 |;
 
-  if ($myconfig{printer} && $latex_templates && $form->{media} ne 'email') {
+  if ($myconfig{printer} && $main::latex_templates && $form->{media} ne 'email') {
     $output .= qq|
       <td>| . $locale->text('Copies') . qq|
       <input name=copies size=2 value=$form->{copies}></td>
@@ -2450,15 +2564,19 @@ sub print_options {
 
   print $output unless $dont_print;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $output;
 }
 
 sub generate_bwa {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('report');
+  $main::auth->assert('report');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{padding} = "&nbsp;&nbsp;";
   $form->{bold}    = "<b>";
@@ -2521,7 +2639,7 @@ sub generate_bwa {
         $form->{fromdate} = "1.2.$form->{year}";
 
         #this works from 1901 to 2099, 1900 and 2100 fail.
-        $leap = ($form->{year} % 4 == 0) ? "29" : "28";
+        my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
         $form->{todate}          = "$leap.2.$form->{year}";
         $form->{comparefromdate} = "1.01.$form->{year}";
         $form->{comparetodate}   = "$leap.02.$form->{year}";
@@ -2599,7 +2717,7 @@ sub generate_bwa {
       };
     }
   } else {
-    ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
+    my ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{fromdate});
     $form->{fromdate} = "${dd}.${mm}.${yy}";
     ($yy, $mm, $dd) = $locale->parse_date(\%myconfig, $form->{todate});
     $form->{todate}          = "${dd}.${mm}.${yy}";
@@ -2624,11 +2742,11 @@ sub generate_bwa {
 
     my %germandate = ("dateformat" => "dd.mm.yyyy");
 
-    $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
-    $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
+    my $longtodate  = $locale->date(\%germandate, $form->{todate}, 1);
+    my $shorttodate = $locale->date(\%germandate, $form->{todate}, 0);
 
-    $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
-    $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
+    my $longfromdate  = $locale->date(\%germandate, $form->{fromdate}, 1);
+    my $shortfromdate = $locale->date(\%germandate, $form->{fromdate}, 0);
 
     $form->{this_period} = "$shortfromdate\n$shorttodate";
     $form->{period}      =
@@ -2639,7 +2757,7 @@ sub generate_bwa {
   }
 
   # setup variables for the form
-  @a = qw(company address businessnumber);
+  my @a = qw(company address businessnumber);
   map { $form->{$_} = $myconfig{$_} } @a;
   $form->{templates} = $myconfig{templates};
 
@@ -2647,6 +2765,7 @@ sub generate_bwa {
 
   $form->parse_template;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
+1;
index 8f09fee..db482fa 100644 (file)
 
 use SL::TODO;
 
+use strict;
+
 sub create_todo_list {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   my %params   = @_;
   my $postfix  = '_login' if ($params{login_screen});
@@ -38,7 +42,7 @@ sub create_todo_list {
   my %todo_cfg = TODO->get_user_config('login' => $form->{login});
 
   if ($params{login_screen} && !$todo_cfg{show_after_login}) {
-    $lxdebug->leave_sub();
+    $main::lxdebug->leave_sub();
     return '';
   }
 
@@ -50,13 +54,16 @@ sub create_todo_list {
   @todo_items = grep { $_ } @todo_items;
   $todo_list  = join("", @todo_items);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $todo_list;
 }
 
 sub show_todo_list {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{todo_list} = create_todo_list();
   $form->{title}     = $locale->text('TODO list');
@@ -64,29 +71,29 @@ sub show_todo_list {
   $form->header();
   print $form->parse_html_template('todo/show_todo_list');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub todo_list_follow_ups {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   require "bin/mozilla/fu.pl";
 
   my $content = report_for_todo_list();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $content;
 }
 
 sub todo_list_overdue_sales_quotations {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   require "bin/mozilla/oe.pl";
 
   my $content = report_for_todo_list();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 
   return $content;
 }
index 69aa541..6d39dda 100644 (file)
@@ -49,6 +49,8 @@ use Data::Dumper;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 # parserhappy(R):
 
 # contents of the "transfer_type" table:
@@ -69,9 +71,13 @@ require "bin/mozilla/reportgenerator.pl";
 # --------------------------------------------------------------------
 
 sub transfer_warehouse_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('warehouse_management');
+  $main::auth->assert('warehouse_management');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
                                      'bins'   => 'BINS', });
@@ -112,13 +118,17 @@ sub transfer_warehouse_selection {
   $form->header();
   print $content;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_parts_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('warehouse_management');
 
-  $auth->assert('warehouse_management');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   transfer_or_removal_prepare_contents('direction' => 'transfer');
 
@@ -126,16 +136,20 @@ sub transfer_parts_selection {
   $form->header();
   print $form->parse_html_template("wh/transfer_parts_selection");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_or_removal_prepare_contents {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('warehouse_management');
+  $main::auth->assert('warehouse_management');
 
   my %args = @_;
 
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
+
   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
                                      'bins'   => 'BINS', });
 
@@ -183,14 +197,18 @@ sub transfer_or_removal_prepare_contents {
   $form->{CONTENTS}       = \@contents;
   $form->{TRANSFER_TYPES} = $transfer_types;
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 
 sub transfer_parts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('warehouse_management');
+  $main::auth->assert('warehouse_management');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->get_lists('warehouses' => { 'key' => 'WAREHOUSES', 'bins' => 'BINS' });
 
@@ -268,7 +286,7 @@ sub transfer_parts {
 
   transfer_warehouse_selection();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -276,7 +294,11 @@ sub transfer_parts {
 # --------------------------------------------------------------------
 
 sub transfer_stock_update_part {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{trans_type} = 'stock';
   $form->{qty}        = $form->parse_amount(\%myconfig, $form->{qty});
@@ -308,7 +330,7 @@ sub transfer_stock_update_part {
     transfer_warehouse_selection();
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -320,7 +342,11 @@ sub transfer_stock_update_part {
 # --------------------------------------------------------------------
 
 sub transfer_assembly_update_part {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{trans_type} = 'assembly';
   $form->{qty}        = $form->parse_amount(\%myconfig, $form->{qty});
@@ -348,30 +374,35 @@ sub transfer_assembly_update_part {
 
 # hier die oben benannte idee
 #    my $maxcreate = Common->check_assembly_max_create(assembly_id => $form->{parts_id}, dbh => $my_dbh);
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
+
 sub transfer_stock_part_selected {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
   my $part = shift;
 
+  my $form     = $main::form;
+
   @{$form}{qw(parts_id partnumber description ean)} = @{$part}{qw(id partnumber description ean)};
 
   transfer_stock_get_partunit();
   transfer_warehouse_selection();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_stock_get_partunit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
 
   if ($form->{parts_id}) {
     my $part_info     = IC->get_basic_part_info('id' => $form->{parts_id});
     $form->{partunit} = $part_info->{unit};
   }
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # vorüberlegung jb 22.2.2009
@@ -382,7 +413,11 @@ sub transfer_stock_get_partunit {
 # Laut Absprache in KW11 09 übernimmt mb hier den rest im April ... jb 18.3.09
 
 sub create_assembly {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
   if ($form->{qty} <= 0) {
@@ -427,11 +462,15 @@ sub create_assembly {
 
   transfer_warehouse_selection();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub transfer_stock {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{qty} = $form->parse_amount(\%myconfig, $form->{qty});
 
@@ -463,7 +502,7 @@ sub transfer_stock {
 
   transfer_warehouse_selection();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -471,9 +510,13 @@ sub transfer_stock {
 # --------------------------------------------------------------------
 
 sub removal_parts_selection {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('warehouse_management');
 
-  $auth->assert('warehouse_management');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   transfer_or_removal_prepare_contents('direction' => 'out');
 
@@ -481,13 +524,17 @@ sub removal_parts_selection {
   $form->header();
   print $form->parse_html_template("wh/removal_parts_selection");
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub remove_parts {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('warehouse_management');
 
-  $auth->assert('warehouse_management');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
                                      'bins'   => 'BINS', });
@@ -566,7 +613,7 @@ sub remove_parts {
 
   transfer_warehouse_selection();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -574,9 +621,12 @@ sub remove_parts {
 # --------------------------------------------------------------------
 
 sub journal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('warehouse_management');
+  $main::auth->assert('warehouse_management');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
 
   $form->get_lists('warehouses' => { 'key'  => 'WAREHOUSES',
                                      'bins' => 'BINS', });
@@ -588,13 +638,17 @@ sub journal {
   $form->header();
   print $form->parse_html_template("wh/journal_filter", { "UNITS" => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_journal {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('warehouse_management');
+  $main::auth->assert('warehouse_management');
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{title}   = $locale->text("WHJournal");
   $form->{sort}  ||= 'date';
@@ -607,8 +661,8 @@ sub generate_journal {
 
   $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
   if ($filter{qty_op}) {
-    $form->isblank(qty,      $locale->text('Quantity missing.'));
-    $form->isblank(qty_unit, $locale->text('Unit missing.'));
+    $form->isblank("qty",      $locale->text('Quantity missing.'));
+    $form->isblank("qty_unit", $locale->text('Unit missing.'));
 
     $filter{qty}      = $form->{qty};
     $filter{qty_unit} = $form->{qty_unit};
@@ -670,7 +724,7 @@ sub generate_journal {
                     'purchase_invoice'        => { script => 'ir', title => $locale->text('Purchase Invoice') },
                   );
 
-  foreach $entry (@contents) {
+  foreach my $entry (@contents) {
     $entry->{qty}        = $form->format_amount_units('amount'     => $entry->{qty},
                                                       'part_unit'  => $entry->{partunit},
                                                       'conv_units' => 'convertible');
@@ -707,7 +761,7 @@ sub generate_journal {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -715,9 +769,13 @@ sub generate_journal {
 # --------------------------------------------------------------------
 
 sub report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('warehouse_contents | warehouse_management');
 
-  $auth->assert('warehouse_contents | warehouse_management');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->get_lists('warehouses' => { 'key'    => 'WAREHOUSES',
                                      'bins'   => 'BINS', });
@@ -734,13 +792,17 @@ sub report {
                                      "WAREHOUSES" => $form->{WAREHOUSES},
                                      "UNITS"      => AM->unit_select_data(AM->retrieve_units(\%myconfig, $form)) });
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub generate_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('warehouse_contents | warehouse_management');
 
-  $auth->assert('warehouse_contents | warehouse_management');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{title}   = $locale->text("Report about wareouse contents");
   $form->{sort}  ||= 'partnumber';
@@ -754,8 +816,8 @@ sub generate_report {
 
   $filter{qty_op} = WH->convert_qty_op($form->{qty_op});
   if ($filter{qty_op}) {
-    $form->isblank(qty,      $locale->text('Quantity missing.'));
-    $form->isblank(qty_unit, $locale->text('Unit missing.'));
+    $form->isblank("qty",      $locale->text('Quantity missing.'));
+    $form->isblank("qty_unit", $locale->text('Unit missing.'));
 
     $filter{qty}      = $form->{qty};
     $filter{qty_unit} = $form->{qty_unit};
@@ -809,7 +871,7 @@ sub generate_report {
 
   my $total_stock_value = 0;
 
-  foreach $entry (@contents) {
+  foreach my $entry (@contents) {
     map { $subtotals{$_} += $entry->{$_} } @subtotals_columns;
     $total_stock_value   += $entry->{stock_value} * 1;
 
@@ -818,7 +880,7 @@ sub generate_report {
                                                        'conv_units' => 'convertible');
     $entry->{stock_value} = $form->format_amount(\%myconfig, $entry->{stock_value} * 1, 2);
 
-    $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
+    my $row_set = [ { map { $_ => { 'data' => $entry->{$_}, 'align' => $column_alignment{$_} } } @columns } ];
 
     if (($form->{subtotal} eq 'Y')
         && (($idx == (scalar @contents - 1))
@@ -856,7 +918,7 @@ sub generate_report {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 # --------------------------------------------------------------------
@@ -864,11 +926,15 @@ sub generate_report {
 # --------------------------------------------------------------------
 
 sub show_no_warehouses_error {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my $msg = $locale->text('No warehouse has been created yet or the quantity of the bins is not configured yet.') . ' ';
 
-  if ($auth->check_right($form->{login}, 'config')) {
+  if ($main::auth->check_right($form->{login}, 'config')) {
     $msg .= $locale->text('You can create warehouses and bins via the menu "System -> Warehouses".');
   } else {
     $msg .= $locale->text('Please ask your administrator to create warehouses and bins.');
@@ -876,12 +942,14 @@ sub show_no_warehouses_error {
 
   $form->show_generic_error($msg);
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub get_warehouse_idx {
   my ($warehouse_id) = @_;
 
+  my $form     = $main::form;
+
   for (my $i = 0; $i < scalar @{$form->{WAREHOUSES}}; $i++) {
     return $i if ($form->{WAREHOUSES}->[$i]->{id} == $warehouse_id);
   }
@@ -892,6 +960,8 @@ sub get_warehouse_idx {
 sub get_bin_idx {
   my ($warehouse_index, $bin_id) = @_;
 
+  my $form     = $main::form;
+
   my $warehouse = $form->{WAREHOUSES}->[$warehouse_index];
 
   return -1 if (!$warehouse);
@@ -915,12 +985,15 @@ sub new_item {
   $main::lxdebug->enter_sub();
   my %params = @_;
 
+  my $form     = $main::form;
+
   # change callback
   $form->{old_callback} = $form->escape($form->{callback}, 1);
   $form->{callback}     = $form->escape("$form->{script}?action=$params{action}", 1);
 
   # save all form variables except action in a previousform variable
   my $previousform = join '&', map { my $value = $form->{$_}; $value =~ s/&/%26/; "$_=$value" } grep { !/action/ } keys %$form;
+  my @HIDDENS = ();
 
 #  push @HIDDENS,      { 'name' => 'previousform', 'value' => $form->escape($previousform, 1) };
   push @HIDDENS, map +{ 'name' => $_,             'value' => $form->{$_} }, qw(partnumber description unit vc sellprice ean);
@@ -934,14 +1007,17 @@ sub new_item {
 }
 
 sub update {
+  my $form     = $main::form;
   call_sub($form->{update_nextsub} || $form->{nextsub});
 }
 
 sub continue {
+  my $form     = $main::form;
   call_sub($form->{continue_nextsub} || $form->{nextsub});
 }
 
 sub stock {
+  my $form     = $main::form;
   call_sub($form->{stock_nextsub} || $form->{nextsub});
 }
 
index 2562892..6ec670a 100644 (file)
@@ -13,15 +13,27 @@ Einige der Regeln lassen sich automatisch 
 
 --------------------------------------------------------------------------
 
-1. Es werden keine "echten" TAB-Zeichen sondern Leerzeichen verwendet.
+1. Es werden keine echten iTabs sondern Leerzeichen verwendet.
 
 2. Die Einrückung beträgt zwei Leerzeichen.
    Beispiel:
 
-   sub debug {
-     print(STDERR "Debugging.\n");
+   foreach my $row (@data) {
+     if ($flag) {
+       # do something with $row
+     }
+
+     if ($use_modules) {
+       $row->{modules} = MODULE->retrieve(
+         id   => $row->{id},
+         date => $use_now ? localtime() : $row->{time},
+       );
+     }
+
+     $report->add($row);
    }
 
+
 3. Öffnende geschweifte Klammern befinden sich auf der gleichen Zeile wie
    der letzte Befehl.
    Beispiele:
@@ -54,10 +66,11 @@ Einige der Regeln lassen sich automatisch 
 
    do {
      ...
-   } while ($a > 0);
+   } until ($a > 0);
 
 6. Parameter von Funktionsaufrufen müssen mit runden Klammern versehen
-   werden. Davon nicht betroffen sind interne perl Funktionen.
+   werden. Davon nicht betroffen sind interne perl Funktionen,
+   und grep ähnliche Operatoren.
 
    Beispiel:
 
@@ -172,3 +185,9 @@ Einige der Regeln lassen sich automatisch 
     Flagmaske, für die die Meldung angezeigt wird, wobei "0" immer angezeigt
     wird. Sollte Meldungen sollten nicht eingecheckt werden, und werden in den
     meisten Fällen auch vom Repository zurückgewiesen.
+
+14. Alle neuen Module müssen use strict verwenden.
+
+    $form, $auth, $locale, $lxdebug, %myconfig sowie der Inhalt der lx-erp.conf
+    werden derzeit aus dem main package importiert. Alle anderen Konstrukte
+    sollten lexikalisch lokal gehalten werden.
diff --git a/kopf.pl b/kopf.pl
index 28ab157..b01c42a 100755 (executable)
--- a/kopf.pl
+++ b/kopf.pl
@@ -1,13 +1,15 @@
 #!/usr/bin/perl
 #
 
+use strict;
+
 BEGIN {
   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 }
 
 use SL::LXDebug;
-$lxdebug = LXDebug->new();
+our $lxdebug = LXDebug->new();
 
 use SL::Auth;
 use SL::Form;
@@ -16,7 +18,7 @@ use SL::Locale;
 eval { require "config/lx-erp.conf"; };
 eval { require "config/lx-erp-local.conf"; } if (-f "config/lx-erp-local.conf");
 
-$form = new Form;
+our $form = new Form;
 
 our $auth     = SL::Auth->new();
 if (!$auth->session_tables_present()) {
@@ -27,7 +29,7 @@ $auth->restore_session();
 
 our %myconfig = $auth->read_user($form->{login});
 
-$locale = new Locale "$myconfig{countrycode}", "kopf";
+our $locale = new Locale "$myconfig{countrycode}", "kopf";
 
 delete $form->{password};
 
index f216dd9..e8a3c5b 100755 (executable)
--- a/login.pl
+++ b/login.pl
 #
 #######################################################################
 
+use strict;
+
 BEGIN {
   unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
   push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
 }
 
 # setup defaults, DO NOT CHANGE
-$userspath  = "users";
-$templates  = "templates";
-$memberfile = "users/members";
-$sendmail   = "| /usr/sbin/sendmail -t";
+$main::userspath  = "users";
+$main::templates  = "templates";
+$main::memberfile = "users/members";
+$main::sendmail   = "| /usr/sbin/sendmail -t";
 ########## end ###########################################
 
 $| = 1;
 
 use SL::LXDebug;
-$lxdebug = LXDebug->new();
+$main::lxdebug = LXDebug->new();
 
 eval { require "config/lx-erp.conf"; };
 eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf";
@@ -62,19 +64,19 @@ if ($ARGV[0]) {
   $_ = $ARGV[0];
 }
 
-%form = split /[&=]/;
+my %form = split /[&=]/;
 
 # fix for apache 2.0 bug
 map { $form{$_} =~ s/\\$// } keys %form;
 
 # name of this script
 $0 =~ tr/\\/\//;
-$pos = rindex $0, '/';
-$script = substr($0, $pos + 1);
+my $pos = rindex $0, '/';
+my $script = substr($0, $pos + 1);
 
-$form->{login} =~ s|.*/||;
+$form{login} =~ s|.*/||;
 
-if (-e "$userspath/nologin" && $script ne 'admin.pl') {
+if (-e "$main::userspath/nologin" && $script ne 'admin.pl') {
   print "content-type: text/plain
 
 Login disabled!\n";
index d70ad89..cc39713 100644 (file)
@@ -70,7 +70,10 @@ foreach my $file (@testitems) {
             if ($file_line1 =~ m#\s-$flags#) {
                 ok(1,"$file uses standard perl location and -$flags");
             } else {
+              TODO: {
+                local $TODO = q(warning isn't supported globally);
                 ok(0,"$file is MISSING -$flags --WARNING");
+              }
             }
         } else {
             ok(0,"$file uses non-standard perl location");
@@ -78,8 +81,6 @@ foreach my $file (@testitems) {
     }
 }
 
-TODO: {
-local $TODO = 'strict is not implemented thoroughly yet';
 foreach my $file (@testitems) {
     my $found_use_strict = 0;
     $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
@@ -101,6 +102,5 @@ foreach my $file (@testitems) {
         ok(0,"$file DOES NOT use strict --WARNING");
     }
 }
-}
 
 exit 0;