return $rc;
}
+sub transfer_out {
+ $::lxdebug->enter_sub;
+
+ my ($self, $form) = @_;
+
+ my @transfers;
+
+ foreach my $i (1 .. $form->{rowcount}) {
+ next if !$form->{"id_$i"};
+ my ($wh_id, $bin_id) = _determine_wh_and_bin($::instance_conf, $form->{"id_$i"});
+
+ if ($wh_id && $bin_id) {
+ push @transfers, {
+ 'parts_id' => $form->{"id_$i"},
+ 'qty' => $form->{"qty_$i"},
+ 'unit' => $form->{"unit_$i"},
+ 'transfer_type' => 'shipped',
+ 'src_warehouse_id' => $wh_id,
+ 'src_bin_id' => $bin_id,
+ 'project_id' => $form->{"project_id_$i"},
+ 'invoice_id' => $form->{"invoice_id_$i"},
+ };
+ }
+ }
+
+ require SL::WH;
+ WH->transfer(@transfers);
+
+ $::lxdebug->leave_sub;
+ return 1;
+}
+
+sub _determine_wh_and_bin {
+ $::lxdebug->enter_sub(2);
+
+ my ($conf, $part_id) = @_;
+
+ my $part = SL::DB::Part->new(id => $part_id)->load;
+
+ if ($part->is_service && !$conf->get_transfer_default_services) {
+ $::lxdebug->leave_sub(2);
+ return;
+ }
+
+
+ my $wh_id = $part->warehouse_id;
+ my $bin_id = $part->bin_id;
+
+ if (!$wh_id && !$bin_id && $conf->get_transfer_default_ignore_onhand) {
+ $wh_id = $conf->get_warehouse_id_ignore_onhand;
+ $bin_id = $conf->get_bin_id_ignore_onhand;
+ }
+
+ $::lxdebug->leave_sub(2);
+ return ($wh_id, $bin_id);
+}
+
sub _delete_payments {
$main::lxdebug->enter_sub();
trans_id => $trans_id,
shippingdate => !$transfer->{shippingdate} || $transfer->{shippingdate} eq 'current_date'
? $now : $transfer->{shippingdate},
- map { $_ => $transfer->{$_} } qw( chargenumber bestbefore oe_id delivery_order_items_stock_id comment),
+ map { $_ => $transfer->{$_} } qw(chargenumber bestbefore oe_id delivery_order_items_stock_id invoice_id comment),
);
if ($unit) {
use DateTime;
use List::MoreUtils qw(uniq);
use List::Util qw(max sum);
+use English qw(-no_match_vars);
use SL::DB::Default;
use SL::DB::Customer;
}
relink_accounts();
- $form->error($locale->text('Cannot post invoice!'))
- unless IS->post_invoice(\%myconfig, \%$form);
+
+ # 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) {
+ require SL::DB::Inventory;
+ my $rose_db = SL::DB::Inventory->new->db;
+ my $error;
+
+ if (!$rose_db->with_transaction(sub {
+ if (!eval {
+ IS->post_invoice(\%myconfig, \%$form, $rose_db->dbh);
+ IS->transfer_out(\%$form);
+ 1;
+ }) {
+ $error = $EVAL_ERROR;
+ return;
+ }
+
+ 1;
+ })) {
+ $form->error($locale->text("Cannot post invoice and/or transfer out!\nError was:\n") . $locale->text($error));
+ }
+ } else {
+ if (!IS->post_invoice(\%myconfig, \%$form)) {
+ $form->error($locale->text('Cannot post invoice!'));
+ }
+ }
+
remove_draft() if $form->{remove_draft};
if(!exists $form->{addition}) {