use SL::ARAP;
use SL::Common;
use SL::CVar;
+use SL::DATEV qw(:CONSTANTS);
use SL::DBUtils;
use SL::DO;
use SL::GenericTranslations;
next if $payments_only;
- # update parts table
+ # update parts table by setting lastcost to current price, don't allow negative values by using abs
$query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|;
- @values = ($form->{"sellprice_$i"}, conv_i($form->{"id_$i"}));
+ @values = (abs($form->{"sellprice_$i"}), conv_i($form->{"id_$i"}));
do_query($form, $dbh, $query, @values);
# check if we sold the item already and
'arap_id' => $form->{id},
'table' => 'ap',);
+ # safety check datev export
+ if ($::lx_office_conf{datev_check}{check_on_purchase_invoice}) {
+ my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : 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;
+ }
+ }
+
my $rc = 1;
if (!$provided_dbh) {
$rc = $dbh->commit();