$self->{trans_id} = $_[0];
}
+ die "illegal trans_id passed for DATEV export: " . $self->{trans_id} . "\n" unless $self->{trans_id} =~ m/^\d+$/;
+
return $self->{trans_id};
}
sub _get_transactions {
$main::lxdebug->enter_sub();
my $self = shift;
- my $fromto = shift;
+ my $fromto = shift;
my $progress_callback = shift || sub {};
my $form = $main::form;
my $trans_id_filter = '';
- $trans_id_filter = 'AND ac.trans_id = ' . $self->trans_id if $self->trans_id;
+ if ( $self->{trans_id} ) {
+ # ignore dates when trans_id is passed so that the entire transaction is
+ # checked, not just either the initial bookings or the subsequent payments
+ # (the transdates will likely differ)
+ $fromto = '';
+ $trans_id_filter = 'ac.trans_id = ' . $self->trans_id;
+ } else {
+ $fromto =~ s/transdate/ac\.transdate/g;
+ };
my ($notsplitindex);
- $fromto =~ s/transdate/ac\.transdate/g;
-
my $filter = ''; # Useful for debugging purposes
my %all_taxchart_ids = selectall_as_map($form, $self->dbh, qq|SELECT DISTINCT chart_id, TRUE AS is_set FROM tax|, 'chart_id', 'is_set');
$self->{DATEV} = [];
my $counter = 0;
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+ my $continue = 1; #
+ my $name;
+ while ( $continue && (my $ref = $sth->fetchrow_hashref("NAME_lc")) ) {
+ last unless $ref; # for single transactions
$counter++;
if (($counter % 500) == 0) {
$progress_callback->($counter);
# keep fetching new acc_trans lines until the end of a balanced group is reached
while (abs($count) > 0.01 || $firstrun || ($subcent && abs($count) > 0.005)) {
my $ref2 = $sth->fetchrow_hashref("NAME_lc");
- last unless ($ref2);
+ unless ( $ref2 ) {
+ $continue = 0;
+ last;
+ };
# check if trans_id of current acc_trans line is still the same as the
- # trans_id of the first line in group
+ # trans_id of the first line in group, i.e. we haven't finished a 0-group
+ # before moving on to the next trans_id, error will likely be in the old
+ # trans_id.
if ($ref2->{trans_id} != $trans->[0]->{trans_id}) {
- $self->add_error("Unbalanced ledger! old trans_id " . $trans->[0]->{trans_id} . " new trans_id " . $ref2->{trans_id} . " count $count");
+ require SL::DB::Manager::AccTransaction;
+ if ( $trans->[0]->{trans_id} ) {
+ my $acc_trans_old_obj = SL::DB::Manager::AccTransaction->get_first(where => [ trans_id => $trans->[0]->{trans_id} ]);
+ $self->add_error("Unbalanced ledger! Old: " . $acc_trans_old_obj->transaction_name) if ref($acc_trans_old_obj);
+ };
+ if ( $ref2->{trans_id} ) {
+ my $acc_trans_curr_obj = SL::DB::Manager::AccTransaction->get_first(where => [ trans_id => $ref2->{trans_id} ]);
+ $self->add_error("Unbalanced ledger! New:" . $acc_trans_curr_obj->transaction_name) if ref($acc_trans_curr_obj);
+ };
+ $self->add_error("count: $count");
return;
}
$absumsatz = $form->round_amount($absumsatz, 2);
if (abs($absumsatz) >= (0.01 * (1 + scalar @taxed))) {
- $self->add_error("Datev-Export fehlgeschlagen! Bei Transaktion $trans->[0]->{trans_id} ($absumsatz)");
+ require SL::DB::Manager::AccTransaction;
+ my $acc_trans_obj = SL::DB::Manager::AccTransaction->get_first(where => [ trans_id => $trans->[0]->{trans_id} ]);
+ $self->add_error("Datev-Export fehlgeschlagen! Bei Transaktion " . $acc_trans_obj->transaction_name . " ($absumsatz)");
} elsif (abs($absumsatz) >= 0.01) {
$self->add_net_gross_differences($absumsatz);
use SL::DATEV qw(:CONSTANTS);
+ my $startdate = DateTime->new(year => 2014, month => 9, day => 1);
+ my $enddate = DateTime->new(year => 2014, month => 9, day => 31);
my $datev = SL::DATEV->new(
exporttype => DATEV_ET_BUCHUNGEN,
format => DATEV_FORMAT_KNE,
to => $enddate,
);
+ # To only export transactions from a specific trans_id: (from and to are ignored)
+ my $invoice = SL::DB::Manager::Invoice->find_by( invnumber => '216' );
+ my $datev = SL::DATEV->new(
+ exporttype => DATEV_ET_BUCHUNGEN,
+ format => DATEV_FORMAT_KNE,
+ trans_id => $invoice->trans_id,
+ );
+
my $datev = SL::DATEV->new(
exporttype => DATEV_ET_STAMM,
format => DATEV_FORMAT_KNE,
my $hashref = $datev->get_datev_stamm;
$datev->save_datev_stamm($hashref);
- # manually clean up temporary directories
+ # manually clean up temporary directories older than 8 hours
$datev->clean_temporary_directories;
# export
=item new PARAMS
-Generic constructor. See section attributes for information about hat to pass.
+Generic constructor. See section attributes for information about what to pass.
=item get_datev_stamm
=item filenames
-Returns a list of filenames generated by this DATEV object. This only works if th files were generated during it's lifetime, not if the object was created from a download_token.
+Returns a list of filenames generated by this DATEV object. This only works if the files were generated during its lifetime, not if the object was created from a download_token.
=item net_gross_differences
=item to
-Set boundary dates for the export. Currently thse MUST be set for the export to work.
+Set boundary dates for the export. Unless a trans_id is passed these MUST be
+set for the export to work.
+
+=item trans_id
+
+To check only one gl/ar/ap transaction, pass the trans_id. The attributes
+L<from> and L<to> are currently still needed for the query to be assembled
+correctly.
=item accnofrom
=item *
-OBE rxport was called, which is not yet implemented.
+OBE export was called, which is not yet implemented.
=item *
=item *
C<Datev-Export fehlgeschlagen! Bei Transaktion %d (%f).> This error occurs if a
-transaction could not be reliably sorted out, or had rounding errors over the acceptable threshold.
+transaction could not be reliably sorted out, or had rounding errors above the acceptable threshold.
=back
=item *
-Handling of Vollvorlauf is currently not fully implemented. You must provide both from and to to get a working export.
+Handling of Vollvorlauf is currently not fully implemented. You must provide both from and to in order to get a working export.
=item *