Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f5c454e3

Von Niclas Zimmermann vor mehr als 10 Jahren hinzugefügt

  • ID f5c454e3855012bdb1928f3e4c4964403d4d8163
  • Vorgänger b989d7cf
  • Nachfolger f99b7288

Steuerzonen und Buchungsgruppen bearbeiten

Nachdem man Steuerzonen und Buchungsgruppen auf Datenbankebene
bearbeiten kann, ist jetzt auch eine Bearbeitung an der Ober-
fläche möglich.

Alter Code, der für die Anzeige/Bearbeitung/Erstellung von
Buchungsgruppen entwickelt wurde hat nicht mehr funktioniert
und wurde vollständig ersetzt.

Unterschiede anzeigen:

SL/AM.pm
739 739
  $main::lxdebug->leave_sub();
740 740
}
741 741

  
742

  
743
sub buchungsgruppe {
744
  $main::lxdebug->enter_sub();
745

  
746
  my ($self, $myconfig, $form) = @_;
747

  
748
  # connect to database
749
  my $dbh = $form->dbconnect($myconfig);
750
  # TODO: extract information about income/expense accounts from new table taxzone_chart
751
  my $query = qq|SELECT id, description,
752
                 inventory_accno_id,
753
                 (SELECT accno FROM chart WHERE id = inventory_accno_id) AS inventory_accno
754
                 FROM buchungsgruppen
755
                 ORDER BY sortkey|;
756

  
757
  my $sth = $dbh->prepare($query);
758
  $sth->execute || $form->dberror($query);
759

  
760
  $form->{ALL} = [];
761
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
762
    push @{ $form->{ALL} }, $ref;
763
  }
764

  
765
  $sth->finish;
766
  $dbh->disconnect;
767

  
768
  $main::lxdebug->leave_sub();
769
}
770

  
771
sub get_buchungsgruppe {
772
  $main::lxdebug->enter_sub();
773

  
774
  my ($self, $myconfig, $form) = @_;
775
  my $query;
776

  
777
  # connect to database
778
  my $dbh = $form->dbconnect($myconfig);
779

  
780
  if ($form->{id}) {
781
    # TODO: extract information about income/expense accounts from new table taxzone_chart
782
    $query =
783
      qq|SELECT description, inventory_accno_id,
784
         (SELECT accno FROM chart WHERE id = inventory_accno_id) AS inventory_accno
785
         FROM buchungsgruppen
786
         WHERE id = ?|;
787
    my $sth = $dbh->prepare($query);
788
    $sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})");
789

  
790
    my $ref = $sth->fetchrow_hashref("NAME_lc");
791

  
792
    map { $form->{$_} = $ref->{$_} } keys %$ref;
793

  
794
    $sth->finish;
795

  
796
    $query =
797
      qq|SELECT count(id) = 0 AS orphaned
798
         FROM parts
799
         WHERE buchungsgruppen_id = ?|;
800
    ($form->{orphaned}) = selectrow_query($form, $dbh, $query, $form->{id});
801
  }
802

  
803
  $query = "SELECT inventory_accno_id, income_accno_id, expense_accno_id ".
804
    "FROM defaults";
805
  ($form->{"std_inventory_accno_id"}, $form->{"std_income_accno_id"},
806
   $form->{"std_expense_accno_id"}) = selectrow_query($form, $dbh, $query);
807

  
808
  my $module = "IC";
809
  $query = qq|SELECT c.accno, c.description, c.link, c.id,
810
              d.inventory_accno_id, d.income_accno_id, d.expense_accno_id
811
              FROM chart c, defaults d
812
              WHERE c.link LIKE '%$module%'
813
              ORDER BY c.accno|;
814

  
815

  
816
  my $sth = $dbh->prepare($query);
817
  $sth->execute || $form->dberror($query);
818
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
819
    foreach my $key (split(/:/, $ref->{link})) {
820
      if (!$form->{"std_inventory_accno_id"} && ($key eq "IC")) {
821
        $form->{"std_inventory_accno_id"} = $ref->{"id"};
822
      }
823
      if ($key =~ /$module/) {
824
        if (   ($ref->{id} eq $ref->{inventory_accno_id})
825
            || ($ref->{id} eq $ref->{income_accno_id})
826
            || ($ref->{id} eq $ref->{expense_accno_id})) {
827
          push @{ $form->{"${module}_links"}{$key} },
828
            { accno       => $ref->{accno},
829
              description => $ref->{description},
830
              selected    => "selected",
831
              id          => $ref->{id} };
832
        } else {
833
          push @{ $form->{"${module}_links"}{$key} },
834
            { accno       => $ref->{accno},
835
              description => $ref->{description},
836
              selected    => "",
837
              id          => $ref->{id} };
838
        }
839
      }
840
    }
841
  }
842
  $sth->finish;
843

  
844

  
845
  $dbh->disconnect;
846

  
847
  $main::lxdebug->leave_sub();
848
}
849

  
850
sub save_buchungsgruppe {
851
  $main::lxdebug->enter_sub();
852

  
853
  my ($self, $myconfig, $form) = @_;
854

  
855
  # connect to database
856
  my $dbh = $form->dbconnect($myconfig);
857

  
858
  my @values = ($form->{description}, $form->{inventory_accno_id},
859
                $form->{income_accno_id_0}, $form->{expense_accno_id_0},
860
                $form->{income_accno_id_1}, $form->{expense_accno_id_1},
861
                $form->{income_accno_id_2}, $form->{expense_accno_id_2},
862
                $form->{income_accno_id_3}, $form->{expense_accno_id_3});
863

  
864
  my $query;
865

  
866
  # id is the old record
867
  if ($form->{id}) {
868
    $query = qq|UPDATE buchungsgruppen SET
869
                description = ?, inventory_accno_id = ?,
870
                income_accno_id_0 = ?, expense_accno_id_0 = ?,
871
                income_accno_id_1 = ?, expense_accno_id_1 = ?,
872
                income_accno_id_2 = ?, expense_accno_id_2 = ?,
873
                income_accno_id_3 = ?, expense_accno_id_3 = ?
874
                WHERE id = ?|;
875
    push(@values, $form->{id});
876
  } else {
877
    $query = qq|SELECT COALESCE(MAX(sortkey) + 1, 1) FROM buchungsgruppen|;
878
    my ($sortkey) = $dbh->selectrow_array($query);
879
    $form->dberror($query) if ($dbh->err);
880
    push(@values, $sortkey);
881
    $query = qq|INSERT INTO buchungsgruppen
882
                (description, inventory_accno_id,
883
                income_accno_id_0, expense_accno_id_0,
884
                income_accno_id_1, expense_accno_id_1,
885
                income_accno_id_2, expense_accno_id_2,
886
                income_accno_id_3, expense_accno_id_3,
887
                sortkey)
888
                VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
889
  }
890
  do_query($form, $dbh, $query, @values);
891

  
892
  $dbh->disconnect;
893

  
894
  $main::lxdebug->leave_sub();
895
}
896

  
897
sub delete_buchungsgruppe {
898
  $main::lxdebug->enter_sub();
899

  
900
  my ($self, $myconfig, $form) = @_;
901

  
902
  # connect to database
903
  my $dbh = $form->dbconnect($myconfig);
904

  
905
  my $query = qq|DELETE FROM buchungsgruppen WHERE id = ?|;
906
  do_query($form, $dbh, $query, $form->{id});
907

  
908
  $dbh->disconnect;
909

  
910
  $main::lxdebug->leave_sub();
911
}
912

  
913
sub swap_sortkeys {
914
  $main::lxdebug->enter_sub();
915

  
916
  my ($self, $myconfig, $form, $table) = @_;
917

  
918
  # connect to database
919
  my $dbh = $form->get_standard_dbh($myconfig);
920

  
921
  my $query =
922
    qq|SELECT
923
       (SELECT sortkey FROM $table WHERE id = ?) AS sortkey1,
924
       (SELECT sortkey FROM $table WHERE id = ?) AS sortkey2|;
925
  my @values   = ($form->{"id1"}, $form->{"id2"});
926
  my @sortkeys = selectrow_query($form, $dbh, $query, @values);
927

  
928
  $query  = qq|UPDATE $table SET sortkey = ? WHERE id = ?|;
929
  my $sth = prepare_query($form, $dbh, $query);
930

  
931
  do_statement($form, $sth, $query, $sortkeys[1], $form->{"id1"});
932
  do_statement($form, $sth, $query, $sortkeys[0], $form->{"id2"});
933

  
934
  $sth->finish();
935

  
936
  $dbh->commit();
937

  
938
  $main::lxdebug->leave_sub();
939
}
940

  
941 742
sub prepare_template_filename {
942 743
  $main::lxdebug->enter_sub();
943 744

  

Auch abrufbar als: Unified diff