Revision d38be021
Von Udo Spallek vor etwa 17 Jahren hinzugefügt
SL/AM.pm | ||
---|---|---|
2055 | 2055 |
$main::lxdebug->leave_sub(); |
2056 | 2056 |
} |
2057 | 2057 |
|
2058 |
sub taxes { |
|
2059 |
$main::lxdebug->enter_sub(); |
|
2060 |
|
|
2061 |
my ($self, $myconfig, $form) = @_; |
|
2062 |
|
|
2063 |
# connect to database |
|
2064 |
my $dbh = $form->dbconnect($myconfig); |
|
2065 |
|
|
2066 |
my $query = qq|SELECT |
|
2067 |
t.id, |
|
2068 |
t.taxkey, |
|
2069 |
t.taxdescription, |
|
2070 |
round(t.rate, 2) * 100 AS rate, |
|
2071 |
c.accno AS taxnumber, |
|
2072 |
c.description AS account_description |
|
2073 |
FROM tax t |
|
2074 |
JOIN chart c on (chart_id = c.id) |
|
2075 |
ORDER BY taxkey|; |
|
2076 |
|
|
2077 |
$sth = $dbh->prepare($query); |
|
2078 |
$sth->execute || $form->dberror($query); |
|
2079 |
|
|
2080 |
$form->{TAX} = []; |
|
2081 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
2082 |
push @{ $form->{TAX} }, $ref; |
|
2083 |
} |
|
2084 |
|
|
2085 |
$sth->finish; |
|
2086 |
$dbh->disconnect; |
|
2087 |
|
|
2088 |
$main::lxdebug->leave_sub(); |
|
2089 |
} |
|
2090 |
|
|
2091 |
sub get_tax_accounts { |
|
2092 |
$main::lxdebug->enter_sub(); |
|
2093 |
|
|
2094 |
my ($self, $myconfig, $form) = @_; |
|
2095 |
|
|
2096 |
my $dbh = $form->dbconnect($myconfig); |
|
2097 |
|
|
2098 |
# get Accounts from chart |
|
2099 |
my $query = qq{ SELECT |
|
2100 |
id, |
|
2101 |
accno || ' - ' || description AS _taxaccount |
|
2102 |
FROM chart |
|
2103 |
WHERE link LIKE '%_tax%' |
|
2104 |
ORDER BY accno |
|
2105 |
}; |
|
2106 |
|
|
2107 |
$sth = $dbh->prepare($query); |
|
2108 |
$sth->execute || $form->dberror($query); |
|
2109 |
|
|
2110 |
$form->{ACCOUNTS} = []; |
|
2111 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
2112 |
push @{ $form->{ACCOUNTS} }, $ref; |
|
2113 |
} |
|
2114 |
|
|
2115 |
$sth->finish; |
|
2116 |
|
|
2117 |
$dbh->disconnect; |
|
2118 |
|
|
2119 |
$main::lxdebug->leave_sub(); |
|
2120 |
} |
|
2121 |
|
|
2122 |
sub get_tax { |
|
2123 |
$main::lxdebug->enter_sub(); |
|
2124 |
|
|
2125 |
my ($self, $myconfig, $form) = @_; |
|
2126 |
|
|
2127 |
# connect to database |
|
2128 |
my $dbh = $form->dbconnect($myconfig); |
|
2129 |
|
|
2130 |
my $query = qq|SELECT |
|
2131 |
taxkey, |
|
2132 |
taxdescription, |
|
2133 |
round(rate, 2) * 100 AS rate, |
|
2134 |
chart_id |
|
2135 |
FROM tax |
|
2136 |
WHERE id = ? |; |
|
2137 |
|
|
2138 |
my $sth = $dbh->prepare($query); |
|
2139 |
$sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); |
|
2140 |
|
|
2141 |
my $ref = $sth->fetchrow_hashref(NAME_lc); |
|
2142 |
|
|
2143 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
|
2144 |
|
|
2145 |
$sth->finish; |
|
2146 |
|
|
2147 |
# see if it is used by a taxkey |
|
2148 |
$query = qq|SELECT count(*) FROM taxkeys |
|
2149 |
WHERE tax_id = ?|; |
|
2150 |
|
|
2151 |
($form->{orphaned}) = selectrow_query($form, $dbh, $query, $form->{id}); |
|
2152 |
|
|
2153 |
$form->{orphaned} = !$form->{orphaned}; |
|
2154 |
$sth->finish; |
|
2155 |
|
|
2156 |
if (!$form->{orphaned} ) { |
|
2157 |
$query = qq|SELECT DISTINCT c.id, c.accno |
|
2158 |
FROM taxkeys tk |
|
2159 |
LEFT JOIN tax t ON (t.id = tk.tax_id) |
|
2160 |
LEFT JOIN chart c ON (c.id = tk.chart_id) |
|
2161 |
WHERE tk.tax_id = ?|; |
|
2162 |
|
|
2163 |
$sth = $dbh->prepare($query); |
|
2164 |
$sth->execute($form->{id}) || $form->dberror($query . " ($form->{id})"); |
|
2165 |
|
|
2166 |
$form->{TAXINUSE} = []; |
|
2167 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
2168 |
push @{ $form->{TAXINUSE} }, $ref; |
|
2169 |
} |
|
2170 |
|
|
2171 |
$sth->finish; |
|
2172 |
} |
|
2173 |
|
|
2174 |
$dbh->disconnect; |
|
2175 |
|
|
2176 |
$main::lxdebug->leave_sub(); |
|
2177 |
} |
|
2178 |
|
|
2179 |
sub save_tax { |
|
2180 |
$main::lxdebug->enter_sub(); |
|
2181 |
|
|
2182 |
my ($self, $myconfig, $form) = @_; |
|
2183 |
|
|
2184 |
# connect to database |
|
2185 |
my $dbh = $form->dbconnect($myconfig); |
|
2186 |
|
|
2187 |
$form->{rate} = $form->{rate} / 100; |
|
2188 |
|
|
2189 |
my @values = ($form->{taxkey}, $form->{taxdescription}, $form->{rate}, $form->{chart_id} ); |
|
2190 |
if ($form->{id}) { |
|
2191 |
$query = qq|UPDATE _tax SET |
|
2192 |
taxkey = ?, |
|
2193 |
taxdescription = ?, |
|
2194 |
rate = ?, |
|
2195 |
chart_id = ? |
|
2196 |
WHERE id = ?|; |
|
2197 |
push(@values, $form->{id}); |
|
2198 |
} |
|
2199 |
else { |
|
2200 |
#ok |
|
2201 |
$query = qq|INSERT INTO _tax ( |
|
2202 |
taxkey, |
|
2203 |
taxdescription, |
|
2204 |
rate, |
|
2205 |
chart_id |
|
2206 |
) |
|
2207 |
VALUES (?, ?, ?, ? )|; |
|
2208 |
} |
|
2209 |
do_query($form, $dbh, $query, @values); |
|
2210 |
|
|
2211 |
$dbh->disconnect; |
|
2212 |
|
|
2213 |
$main::lxdebug->leave_sub(); |
|
2214 |
} |
|
2215 |
|
|
2216 |
sub delete_tax { |
|
2217 |
$main::lxdebug->enter_sub(); |
|
2218 |
|
|
2219 |
my ($self, $myconfig, $form) = @_; |
|
2220 |
|
|
2221 |
# connect to database |
|
2222 |
my $dbh = $form->dbconnect($myconfig); |
|
2223 |
|
|
2224 |
$query = qq|DELETE FROM _tax |
|
2225 |
WHERE id = ?|; |
|
2226 |
do_query($form, $dbh, $query, $form->{id}); |
|
2227 |
|
|
2228 |
$dbh->disconnect; |
|
2229 |
|
|
2230 |
$main::lxdebug->leave_sub(); |
|
2231 |
} |
|
2232 |
|
|
2233 |
|
|
2234 |
|
|
2058 | 2235 |
1; |
Auch abrufbar als: Unified diff
Neues Modul 'Steuern Bearbeiten'. Mit diesem Modul ist es moeglich, die Eintraege der Tabelle tax, bzw. _tax anpassen zu koennen.