my $all_units = AM->retrieve_units($myconfig, $form);
if (!$payments_only) {
+ if ($form->{storno}) {
+ _delete_transfers($dbh, $form, $form->{storno_id});
+ }
if ($form->{id}) {
&reverse_invoice($dbh, $form);
+ _delete_transfers($dbh, $form, $form->{id});
} else {
my $trans_number = SL::TransNumber->new(type => $form->{type}, dbh => $dbh, number => $form->{invnumber}, save => 1);
return ($wh_id, $bin_id);
}
+sub _delete_transfers {
+ $::lxdebug->enter_sub;
+
+ my ($dbh, $form, $id) = @_;
+
+ my $query = qq|DELETE FROM inventory WHERE invoice_id
+ IN (SELECT id FROM invoice WHERE trans_id = ?)|;
+
+ do_query($form, $dbh, $query, $id);
+
+ $::lxdebug->leave_sub;
+}
+
sub _delete_payments {
$main::lxdebug->enter_sub();
my $dbh = $form->get_standard_dbh;
&reverse_invoice($dbh, $form);
+ _delete_transfers($dbh, $form, $form->{id});
my @values = (conv_i($form->{id}));
# If transfer_out is requested, get rose db handle and do post and
# transfer out in one transaction. Otherwise just post the invoice.
- if ($::instance_conf->get_is_transfer_out) {
+ if ($::instance_conf->get_is_transfer_out && $form->{type} ne 'credit_note' && !$form->{storno}) {
require SL::DB::Inventory;
my $rose_db = SL::DB::Inventory->new->db;
my $error;