use strict;
use SL::DBUtils;
-use SL::DB::Shop;
use SL::DB::MetaSetup::ShopOrder;
use SL::DB::Manager::ShopOrder;
-use SL::DB::PaymentTerm;
use SL::DB::Helper::LinkedRecords;
use SL::Locale::String qw(t8);
use Carp;
my $customer = delete $params{customer};
my $employee = delete $params{employee};
my $transdate = delete $params{transdate} // DateTime->today_local;
+
croak "param customer is missing" unless ref($customer) eq 'SL::DB::Customer';
croak "param employee is missing" unless ref($employee) eq 'SL::DB::Employee';
+ # check if caller wants optional partial transfer and create partial soi array
+ my $partial_transfer;
+ my %pos_ids;
+ if ($params{pos_ids}) {
+ $partial_transfer = 1;
+ %pos_ids = %{ delete $params{pos_ids} };
+ # TODO check if pos_ids is a valid hash
+ }
+ my @soi = $partial_transfer
+ ? grep { $pos_ids{$_->id} } @{ $self->shop_order_items }
+ : @{ $self->shop_order_items };
+
require SL::DB::Order;
+ use SL::DB::Order::TypeData qw(:types);
require SL::DB::OrderItem;
require SL::DB::Part;
require SL::DB::Shipto;
+ require SL::DB::Shop;
my @error_report;
my @items = map{
unit => $part->unit,
position => $_->position,
active_price_source => $_->active_price_source,
+ discount => $_->discount,
);
}
- }@{ $self->shop_order_items };
-
+ } @soi;
if(!scalar(@error_report)){
my $shipto_id;
currency_id => $customer->currency_id,
transaction_description => $shop->transaction_description,
transdate => $transdate,
+ record_type => SALES_ORDER_TYPE(),
);
return $order;
}else{
obsolete => 'F',
);
}
- $customer->update_attributes(invoice_mail => $self->billing_email) if $customer->invoice_mail ne $self->billing_email;
+ if( ref $customer eq 'SL::DB::Customer') {
+ $customer->update_attributes(invoice_mail => $self->billing_email) if $customer->invoice_mail ne $self->billing_email;
+ }
return $customer;
}