Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ee53bdf9

Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt

  • ID ee53bdf9c4e9092b881ef098f2a7ea55c86ca81d
  • Vorgänger d338ab57
  • Nachfolger 6b8ce220

Kosmetik (nachlaufende Leerzeichen entfernt).

Unterschiede anzeigen:

SL/USTVA.pm
28 28
use SL::DBUtils;
29 29

  
30 30
sub get_coa {
31
  
31

  
32 32
  my ( $self, $form, $myconfig) = @_;
33
  
33

  
34 34
  my $query = q{ SELECT coa FROM defaults };
35
  
35

  
36 36
  my $dbh = $form->dbconnect($myconfig);
37 37
  my $sth = $dbh->prepare($query);
38 38
  $sth->execute() || $form->dberror($query);
39 39

  
40
  my ($coa) = selectrow_query($form, $dbh, $query);  
41
  
40
  my ($coa) = selectrow_query($form, $dbh, $query);
41

  
42 42
  $sth->finish;
43 43
  $dbh->disconnect;
44
  
44

  
45 45
  $form->{coa} = $coa;
46 46
  $form->{"COA_$coa"} = '1';
47 47
  $form->{COA_Germany} = '1' if ( $coa eq 'Germany-DATEV-SKR03EU' or $coa eq 'Germany-DATEV-SKR04EU');
......
53 53
sub report_variables {
54 54
  # Get all positions for taxreport out of the database
55 55
  # Needs Databaseupdate Pg-upgrade2/USTVA_abstraction.pl
56
  
56

  
57 57
  return unless defined wantarray;
58
  
58

  
59 59
  my ( $self,
60 60
       $arg_ref) = @_;
61
       
61

  
62 62
  my $myconfig   = $arg_ref->{myconfig};
63 63
  my $form       = $arg_ref->{form};
64 64
  my $type       = $arg_ref->{type}; # 'paied' || 'received' || ''
65
  my $attribute  = $arg_ref->{attribute}; # 
65
  my $attribute  = $arg_ref->{attribute}; #
66 66
  my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
67 67

  
68 68
  my $where_type = "AND tax.report_headings.type = '$type'" if ( $type );
......
70 70

  
71 71
  my $query = qq|
72 72
    SELECT $attribute
73
    FROM tax.report_variables 
74
    LEFT JOIN tax.report_headings 
73
    FROM tax.report_variables
74
    LEFT JOIN tax.report_headings
75 75
      ON (tax.report_variables.heading_id = tax.report_headings.id)
76
    WHERE 1=1 
76
    WHERE 1=1
77 77
    $where_type
78
    $where_dcp  
78
    $where_dcp
79 79
  |;
80
  
80

  
81 81
  my $dbh = $form->dbconnect($myconfig);
82 82
  my $sth = $dbh->prepare($query);
83 83

  
84 84
  $sth->execute() || $form->dberror($query);
85
  
85

  
86 86
  my @positions;
87
  
87

  
88 88
  while ( my $row_ref = $sth->fetchrow_arrayref() ) {
89 89
    push @positions, @$row_ref;  # Copy the array contents
90 90
  }
91
  
91

  
92 92
  $sth->finish;
93
  
93

  
94 94
  $dbh->disconnect;
95
  
95

  
96 96
  return @positions;
97
  
97

  
98 98
}
99 99

  
100 100
sub create_steuernummer {
......
138 138
  my ($self, $elsterland, $elsterFFFF, $steuernummer) = @_;
139 139

  
140 140
  my $steuernummer_input = '';
141
  
141

  
142 142
  $elster_land  = $elsterland;
143 143
  $elster_FFFF  = $elsterFFFF;
144 144
  $steuernummer = '0000000000' if ($steuernummer eq '');
......
236 236
      $steuernummer_input .= qq|</select>\n|;
237 237
    }
238 238
  }
239
  
239

  
240 240
  $main::lxdebug->leave_sub();
241
  
241

  
242 242
  return $steuernummer_input;
243 243
}
244 244

  
......
252 252
  # Prototyp f?r diese Konstruktion
253 253

  
254 254
  my ($self, $land, $elsterFFFF, $elster_init) = @_;
255
  
255

  
256 256
  my $terminal = '';
257 257
  my $FFFF     = $elsterFFFF;
258 258
  my $ffff     = '';
......
651 651
      attribute   => 'position',
652 652
      dec_places  => '2',
653 653
  });
654
  
654

  
655 655
  push @category_cent, qw(83  Z43  Z45  Z53  Z62  Z65  Z67);
656
  
656

  
657 657
  my @category_euro = USTVA->report_variables({
658 658
      myconfig    => $myconfig,
659 659
      form        => $form,
......
661 661
      attribute   => 'position',
662 662
      dec_places  => '0',
663 663
  });
664
                           
664

  
665 665
  push @category_euro, USTVA->report_variables({
666 666
      myconfig    => $myconfig,
667 667
      form        => $form,
......
680 680
  }
681 681
  my $coa_name = coa_get($dbh);
682 682
  $form->{coa} = $coa_name;
683
  
683

  
684 684
  # Controlvariable for templates
685 685
  $form->{"$coa_name"} = '1';
686 686

  
......
694 694
  # Nationspecific Modfications
695 695
  #
696 696
  ###########################################
697
  
697

  
698 698
  # Germany
699
  
699

  
700 700
  if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU'){
701
  
701

  
702 702
    # 16%/19% Umstellung
703 703
    # Umordnen der Kennziffern
704 704
    if ( $form->{year} < 2007) {
......
718 718
  }
719 719

  
720 720

  
721
  # Fixme: Wird auch noch f?r Oesterreich gebraucht, 
721
  # Fixme: Wird auch noch f?r Oesterreich gebraucht,
722 722
  # weil kein eigenes Ausgabeformular
723 723
  # sotte aber aus der allgem?inen Steuerberechnung verschwinden
724 724
  #
......
730 730
  $form->{"97r"} = $form->{"971"};
731 731
  $form->{"93r"} = $form->{"931"};
732 732

  
733
  $form->{"Z43"} = $form->{"511"}     + $form->{"811"} + $form->{"861"} 
734
                     + $form->{"36"}  + $form->{"80"}  + $form->{"971"} 
735
                     + $form->{"891"} + $form->{"931"} + $form->{"96"} 
733
  $form->{"Z43"} = $form->{"511"}     + $form->{"811"} + $form->{"861"}
734
                     + $form->{"36"}  + $form->{"80"}  + $form->{"971"}
735
                     + $form->{"891"} + $form->{"931"} + $form->{"96"}
736 736
                     + $form->{"98"};
737 737

  
738 738
  $form->{"Z45"} = $form->{"Z43"};
739 739

  
740
  $form->{"Z53"} = $form->{"Z45"}     + $form->{"53"}  + $form->{"74"}  
740
  $form->{"Z53"} = $form->{"Z45"}     + $form->{"53"}  + $form->{"74"}
741 741
                     + $form->{"85"}  + $form->{"65"};
742
                     
743
  $form->{"Z62"} = $form->{"Z43"}     - $form->{"66"}  - $form->{"61"} 
744
                     - $form->{"62"}  - $form->{"67"}  - $form->{"63"}  
742

  
743
  $form->{"Z62"} = $form->{"Z43"}     - $form->{"66"}  - $form->{"61"}
744
                     - $form->{"62"}  - $form->{"67"}  - $form->{"63"}
745 745
                     - $form->{"64"}  - $form->{"59"};
746
                      
746

  
747 747
  $form->{"Z65"} = $form->{"Z62"}     - $form->{"69"};
748 748
  $form->{"83"}  = $form->{"Z65"}     - $form->{"39"};
749
  
749

  
750 750
  $dbh->disconnect;
751 751

  
752 752
  $main::lxdebug->leave_sub();
......
755 755
sub coa_get {
756 756

  
757 757
  my ($dbh) = @_;
758
  
758

  
759 759
  my $query= qq|SELECT coa FROM defaults|;
760 760

  
761 761
  my $sth = $dbh->prepare($query);
762
  
762

  
763 763
  $sth->execute || $form->dberror($query);
764
    
764

  
765 765
  ($ref) = $sth->fetchrow_array;
766
  
766

  
767 767
  return $ref;
768 768

  
769 769
};
......
788 788
    if ($form->{method} eq 'cash') {
789 789
      $subwhere .= " AND transdate >= '$fromdate'";
790 790
      $glwhere = " AND ac.transdate >= '$fromdate'";
791
      $ARwhere .= " AND acc.transdate >= '$fromdate'"; 
791
      $ARwhere .= " AND acc.transdate >= '$fromdate'";
792 792
    }
793 793
    $APwhere .= " AND AP.transdate >= '$fromdate'";
794 794
    $where .= " AND ac.transdate >= '$fromdate'";
......
821 821
  #
822 822
  ############################################
823 823

  
824
  if ($form->{method} eq 'cash') {  
824
  if ($form->{method} eq 'cash') {
825 825

  
826 826
    $query = qq|
827 827
       SELECT
828 828
         -- USTVA IST-Versteuerung
829
         -- 
830
         -- Alle tatsaechlichen _Zahlungseingaenge_ 
831
         -- im Voranmeldezeitraum erfassen 
829
         --
830
         -- Alle tatsaechlichen _Zahlungseingaenge_
831
         -- im Voranmeldezeitraum erfassen
832 832
         -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
833
         SUM( ac.amount * 
833
         SUM( ac.amount *
834 834
            -- Bezahlt / Rechnungssumme
835
           ( 
835
           (
836 836
             SELECT SUM(acc.amount)
837 837
             FROM acc_trans acc
838
             INNER JOIN chart c ON (acc.chart_id   =   c.id 
838
             INNER JOIN chart c ON (acc.chart_id   =   c.id
839 839
                                    AND c.link   like  '%AR_paid%')
840 840
             WHERE
841
              1=1 
841
              1=1
842 842
              $ARwhere
843 843
              AND acc.trans_id = ac.trans_id
844 844
              )
845
           / 
846
           ( 
847
            SELECT amount FROM ar WHERE id = ac.trans_id  
845
           /
846
           (
847
            SELECT amount FROM ar WHERE id = ac.trans_id
848 848
           )
849 849
         ) AS amount,
850 850
         tk.pos_ustva
......
853 853
       LEFT JOIN ar      ON (ar.id = ac.trans_id)
854 854
       LEFT JOIN taxkeys tk ON (
855 855
         tk.id = (
856
           SELECT id FROM taxkeys 
857
           WHERE chart_id   = ac.chart_id 
858
             -- AND taxkey_id  = ac.taxkey 
856
           SELECT id FROM taxkeys
857
           WHERE chart_id   = ac.chart_id
858
             -- AND taxkey_id  = ac.taxkey
859 859
             AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
860 860
           ORDER BY startdate DESC LIMIT 1
861 861
         )
862 862
       )
863
       WHERE 
863
       WHERE
864 864
       $acc_trans_where
865 865
       GROUP BY tk.pos_ustva
866 866
    |;
867
   
867

  
868 868
  } elsif ($form->{method} eq 'accrual') {
869 869
    #########################################
870 870
    # Method eq 'accrual' = Soll Versteuerung
......
873 873
    $query = qq|
874 874
       -- Alle Einnahmen AR und pos_ustva erfassen
875 875
       SELECT
876
         - sum(ac.amount) AS amount, 
876
         - sum(ac.amount) AS amount,
877 877
         tk.pos_ustva
878
       FROM acc_trans ac 
879
       JOIN chart c ON (c.id = ac.chart_id) 
878
       FROM acc_trans ac
879
       JOIN chart c ON (c.id = ac.chart_id)
880 880
       JOIN ar ON (ar.id = ac.trans_id)
881 881
       JOIN taxkeys tk ON (
882 882
         tk.id = (
883
           SELECT id FROM taxkeys 
884
           WHERE chart_id   = ac.chart_id 
883
           SELECT id FROM taxkeys
884
           WHERE chart_id   = ac.chart_id
885 885
             AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
886 886
           ORDER BY startdate DESC LIMIT 1
887 887
         )
......
891 891
       $where
892 892
       GROUP BY tk.pos_ustva
893 893
  |;
894
   
894

  
895 895
  } else {
896
  
896

  
897 897
    $form->error("Unknown tax method: $form->{method}")
898 898

  
899 899
  }
900
  
900

  
901 901
  #########################################
902 902
  # Ausgaben und Gl Buchungen sind gleich
903 903
  # f?r Ist- und Soll-Versteuerung
904 904
  #########################################
905
  $query .= qq| 
905
  $query .= qq|
906 906
     UNION -- alle Ausgaben AP erfassen
907 907

  
908 908
       SELECT
909
         sum(ac.amount) AS amount, 
909
         sum(ac.amount) AS amount,
910 910
         tk.pos_ustva
911 911
       FROM acc_trans ac
912 912
       JOIN ap ON (ap.id = ac.trans_id )
913 913
       JOIN chart c ON (c.id = ac.chart_id)
914 914
       LEFT JOIN taxkeys tk ON (
915 915
           tk.id = (
916
             SELECT id FROM taxkeys 
916
             SELECT id FROM taxkeys
917 917
             WHERE 1=1
918
               AND chart_id=ac.chart_id 
919
               --AND taxkey_id = ac.taxkey 
918
               AND chart_id=ac.chart_id
919
               --AND taxkey_id = ac.taxkey
920 920
               AND startdate <= COALESCE(AP.transdate)
921 921
             ORDER BY startdate DESC LIMIT 1
922 922
           )
......
929 929
     UNION -- Einnahmen direkter gl Buchungen erfassen
930 930

  
931 931
       SELECT sum
932
         ( - ac.amount) AS amount, 
932
         ( - ac.amount) AS amount,
933 933
         tk.pos_ustva
934 934
       FROM acc_trans ac
935 935
       JOIN chart c ON (c.id = ac.chart_id)
936 936
       JOIN gl a ON (a.id = ac.trans_id)
937 937
       LEFT JOIN taxkeys tk ON (
938 938
         tk.id = (
939
           SELECT id FROM taxkeys 
940
           WHERE chart_id=ac.chart_id 
941
             AND NOT $gltaxkey_where  
939
           SELECT id FROM taxkeys
940
           WHERE chart_id=ac.chart_id
941
             AND NOT $gltaxkey_where
942 942
             AND startdate <= COALESCE(ac.transdate)
943 943
           ORDER BY startdate DESC LIMIT 1
944 944
         )
......
953 953
     UNION -- Ausgaben direkter gl Buchungen erfassen
954 954

  
955 955
       SELECT sum
956
         (ac.amount) AS amount, 
956
         (ac.amount) AS amount,
957 957
         tk.pos_ustva
958 958
       FROM acc_trans ac
959 959
       JOIN chart c ON (c.id = ac.chart_id)
960 960
       JOIN gl a ON (a.id = ac.trans_id)
961 961
       LEFT JOIN taxkeys tk ON (
962 962
         tk.id = (
963
           SELECT id FROM taxkeys 
964
           WHERE chart_id=ac.chart_id 
965
             AND $gltaxkey_where 
963
           SELECT id FROM taxkeys
964
           WHERE chart_id=ac.chart_id
965
             AND $gltaxkey_where
966 966
             AND startdate <= COALESCE(ac.transdate)
967 967
           ORDER BY startdate DESC LIMIT 1
968 968
         )
......
982 982
  # Show all $query in Debuglevel LXDebug::QUERY
983 983
  $callingdetails = (caller (0))[3];
984 984
  $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query");
985
              
985

  
986 986
  my $sth = $dbh->prepare($query);
987
  
987

  
988 988
  $sth->execute || $form->dberror($query);
989 989

  
990 990
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
......
1016 1016
    # create file if file does not exist
1017 1017
    open my $FANEW, ">", $filename  or $form->error("CREATE: $filename : $!");
1018 1018
    close $FANEW                    or $form->error("CLOSE: $filename : $!");
1019
    
1019

  
1020 1020
    #try again open file
1021 1021
    open my $FACONF, "<", $filename or $form->error("OPEN: $filename : $!");
1022 1022
  };

Auch abrufbar als: Unified diff