package GL;
use Data::Dumper;
+use SL::DATEV qw(:CONSTANTS);
use SL::DBUtils;
use strict;
if ($amount != 0) {
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo, project_id, taxkey, ob_transaction, cb_transaction)
+ source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id)
VALUES (?, (SELECT id FROM chart WHERE accno = ?),
- ?, ?, ?, ?, ?, ?, ?, ?)|;
+ ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
@values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}),
- $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f');
+ $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}));
do_query($form, $dbh, $query, @values);
}
# add taxentry
$query =
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
- source, memo, project_id, taxkey)
+ source, memo, project_id, taxkey, tax_id)
VALUES (?, (SELECT chart_id FROM tax WHERE id = ?),
- ?, ?, ?, ?, ?, ?)|;
+ ?, ?, ?, ?, ?, ?, ?)|;
@values = (conv_i($form->{id}), conv_i($form->{"tax_id_$i"}),
$tax, conv_date($form->{transdate}), $form->{"source_$i"},
- $form->{"memo_$i"}, $project_id, $taxkey);
+ $form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"}));
do_query($form, $dbh, $query, @values);
}
}
do_query($form, $dbh, qq|UPDATE gl SET storno = 't' WHERE id = ?|, conv_i($form->{storno_id}));
}
+ # safety check datev export
+ if ($::instance_conf->get_datev_check_on_gl_transaction) {
+ my $transdate = $::form->{transdate} ? DateTime->from_lxoffice($::form->{transdate}) : undef;
+ $transdate ||= DateTime->today;
+
+ my $datev = SL::DATEV->new(
+ exporttype => DATEV_ET_BUCHUNGEN,
+ format => DATEV_FORMAT_KNE,
+ dbh => $dbh,
+ from => $transdate,
+ to => $transdate,
+ );
+
+ $datev->export;
+
+ if ($datev->errors) {
+ $dbh->rollback;
+ die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors;
+ }
+ }
+
# commit and redirect
my $rc = $dbh->commit;
$dbh->disconnect;
(SELECT c1.accno
FROM chart c1, tax t1
WHERE (t1.id = t.id) AND (c1.id = t.chart_id)) AS taxaccno,
- (SELECT tk.tax_id
- FROM taxkeys tk
- WHERE (tk.chart_id = a.chart_id) AND (tk.startdate <= a.transdate)
- ORDER BY tk.startdate desc LIMIT 1) AS tax_id
+ a.tax_id AS tax_id
FROM acc_trans a
JOIN chart c ON (c.id = a.chart_id)
LEFT JOIN project p ON (p.id = a.project_id)
LEFT JOIN tax t ON
- (t.id =
- (SELECT tk.tax_id
- FROM taxkeys tk
- WHERE (tk.taxkey_id = a.taxkey) AND
- ((CASE WHEN a.chart_id IN
- (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
- THEN tk.chart_id = a.chart_id
- ELSE 1 = 1
- END)
- OR (c.link LIKE '%tax%'))
- AND (startdate <= a.transdate)
- ORDER BY startdate DESC LIMIT 1))
+ (t.id = a.tax_id)
WHERE (a.trans_id = ?)
AND (a.fx_transaction = '0')
ORDER BY a.acc_trans_id, a.transdate|;
$storno_row->{storno} = 't';
$storno_row->{reference} = 'Storno-' . $storno_row->{reference};
- delete @$storno_row{qw(itime mtime)};
+ delete @$storno_row{qw(itime mtime gldate)};
$query = sprintf 'INSERT INTO gl (%s) VALUES (%s)', join(', ', keys %$storno_row), join(', ', map '?', values %$storno_row);
do_query($form, $dbh, $query, (values %$storno_row));
my $rowref = selectall_hashref_query($form, $dbh, $query, $id);
for my $row (@$rowref) {
- delete @$row{qw(itime mtime acc_trans_id)};
+ delete @$row{qw(itime mtime acc_trans_id gldate)};
$query = sprintf 'INSERT INTO acc_trans (%s) VALUES (%s)', join(', ', keys %$row), join(', ', map '?', values %$row);
$row->{trans_id} = $new_id;
$row->{amount} *= -1;