]> wagnertech.de Git - mfinanz.git/blobdiff - SL/AM.pm
Anpassung der Routinen von Kreditoren und Debitorenbuchungen auf das neue Steuersystem
[mfinanz.git] / SL / AM.pm
index a4b0c950c0593c5620f84e4e0cdf12d7208749e1..843d5ea63d1b7ab51439de44b5eb3b63f5ccc011 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -640,6 +640,101 @@ sub delete_department {
   $main::lxdebug->leave_sub();
 }
 
+sub lead {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $query = qq|SELECT id, lead
+                 FROM leads
+                ORDER BY 2|;
+
+  $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+    push @{ $form->{ALL} }, $ref;
+  }
+
+  $sth->finish;
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
+sub get_lead {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $query =
+    qq|SELECT l.id, l.lead
+                 FROM leads l
+                WHERE l.id = $form->{id}|;
+  my $sth = $dbh->prepare($query);
+  $sth->execute || $form->dberror($query);
+
+  my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+  map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+  $sth->finish;
+
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
+sub save_lead {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  $form->{lead} =~ s/\'/\'\'/g;
+
+  # id is the old record
+  if ($form->{id}) {
+    $query = qq|UPDATE leads SET
+               lead = '$form->{description}'
+               WHERE id = $form->{id}|;
+  } else {
+    $query = qq|INSERT INTO leads
+                (lead)
+                VALUES ('$form->{description}')|;
+  }
+  $dbh->do($query) || $form->dberror($query);
+
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
+sub delete_lead {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  # connect to database
+  my $dbh = $form->dbconnect($myconfig);
+
+  $query = qq|DELETE FROM leads
+             WHERE id = $form->{id}|;
+  $dbh->do($query) || $form->dberror($query);
+
+  $dbh->disconnect;
+
+  $main::lxdebug->leave_sub();
+}
+
 sub business {
   $main::lxdebug->enter_sub();
 
@@ -903,6 +998,10 @@ sub get_buchungsgruppe {
     $sth->finish;
 
   }
+
+  $query = "SELECT inventory_accno_id FROM defaults";
+  ($form->{"std_inventory_accno_id"}) = $dbh->selectrow_array($query);
+
   my $module = "IC";
   $query = qq|SELECT c.accno, c.description, c.link, c.id,
               d.inventory_accno_id, d.income_accno_id, d.expense_accno_id
@@ -914,7 +1013,10 @@ sub get_buchungsgruppe {
   my $sth = $dbh->prepare($query);
   $sth->execute || $form->dberror($query);
   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-    foreach my $key (split /:/, $ref->{link}) {
+    foreach my $key (split(/:/, $ref->{link})) {
+      if (!$form->{"std_inventory_accno_id"} && ($key eq "IC")) {
+        $form->{"std_inventory_accno_id"} = $ref->{"id"};
+      }
       if ($key =~ /$module/) {
         if (   ($ref->{id} eq $ref->{inventory_accno_id})
             || ($ref->{id} eq $ref->{income_accno_id})
@@ -924,7 +1026,7 @@ sub get_buchungsgruppe {
               description => $ref->{description},
               selected    => "selected",
               id          => $ref->{id} };
-            } else {
+        } else {
           push @{ $form->{"${module}_links"}{$key} },
             { accno       => $ref->{accno},
               description => $ref->{description},
@@ -1096,104 +1198,6 @@ sub delete_printer {
   $main::lxdebug->leave_sub();
 }
 
-sub adr {
-  $main::lxdebug->enter_sub();
-
-  my ($self, $myconfig, $form) = @_;
-
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
-
-  my $query = qq|SELECT id, adr_description, adr_code
-                 FROM adr
-                ORDER BY adr_code|;
-
-  $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
-
-  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-    push @{ $form->{ALL} }, $ref;
-  }
-
-  $sth->finish;
-  $dbh->disconnect;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub get_adr {
-  $main::lxdebug->enter_sub();
-
-  my ($self, $myconfig, $form) = @_;
-
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
-
-  my $query =
-    qq|SELECT a.adr_description, a.adr_code
-                 FROM adr a
-                WHERE a.id = $form->{id}|;
-  my $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
-
-  my $ref = $sth->fetchrow_hashref(NAME_lc);
-
-  map { $form->{$_} = $ref->{$_} } keys %$ref;
-
-  $sth->finish;
-
-  $dbh->disconnect;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub save_adr {
-  $main::lxdebug->enter_sub();
-
-  my ($self, $myconfig, $form) = @_;
-
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
-
-  $form->{adr_description} =~ s/\'/\'\'/g;
-  $form->{adr_code} =~ s/\'/\'\'/g;
-
-
-  # id is the old record
-  if ($form->{id}) {
-    $query = qq|UPDATE adr SET
-               adr_description = '$form->{adr_description}',
-               adr_code = '$form->{adr_code}'
-               WHERE id = $form->{id}|;
-  } else {
-    $query = qq|INSERT INTO adr
-                (adr_description, adr_code)
-                VALUES ('$form->{adr_description}', '$form->{adr_code}')|;
-  }
-  $dbh->do($query) || $form->dberror($query);
-
-  $dbh->disconnect;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub delete_adr {
-  $main::lxdebug->enter_sub();
-
-  my ($self, $myconfig, $form) = @_;
-
-  # connect to database
-  my $dbh = $form->dbconnect($myconfig);
-
-  $query = qq|DELETE FROM adr
-             WHERE id = $form->{id}|;
-  $dbh->do($query) || $form->dberror($query);
-
-  $dbh->disconnect;
-
-  $main::lxdebug->leave_sub();
-}
-
 sub payment {
   $main::lxdebug->enter_sub();
 
@@ -1438,12 +1442,12 @@ sub save_preferences {
 
   my ($self, $myconfig, $form, $memberfile, $userspath, $webdav) = @_;
 
-  map { ($form->{$_}) = split /--/, $form->{$_} }
+  map { ($form->{$_}) = split(/--/, $form->{$_}) }
     qw(inventory_accno income_accno expense_accno fxgain_accno fxloss_accno);
 
   my @a;
   $form->{curr} =~ s/ //g;
-  map { push(@a, uc pack "A3", $_) if $_ } split /:/, $form->{curr};
+  map { push(@a, uc pack "A3", $_) if $_ } split(/:/, $form->{curr});
   $form->{curr} = join ':', @a;
 
   # connect to database
@@ -1493,7 +1497,7 @@ sub save_preferences {
              WHERE login = '$form->{login}'|;
   $dbh->do($query) || $form->dberror($query);
 
-  foreach my $item (split / /, $form->{taxaccounts}) {
+  foreach my $item (split(/ /, $form->{taxaccounts})) {
     $query = qq|UPDATE tax
                SET rate = | . ($form->{$item} / 100) . qq|,
                taxnumber = '$form->{"taxnumber_$item"}'
@@ -1942,16 +1946,14 @@ sub closebooks {
 
     $query = qq|UPDATE defaults SET closedto = NULL,
                                    revtrans = '1'|;
-  } else {
-    if ($form->{closedto}) {
+  } elsif ($form->{closedto}) {
 
-      $query = qq|UPDATE defaults SET closedto = '$form->{closedto}',
+    $query = qq|UPDATE defaults SET closedto = '$form->{closedto}',
                                      revtrans = '0'|;
-    } else {
+  } else {
 
-      $query = qq|UPDATE defaults SET closedto = NULL,
+    $query = qq|UPDATE defaults SET closedto = NULL,
                                      revtrans = '0'|;
-    }
   }
 
   # set close in defaults