X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/ff159a4d47b9a2d10744dcfc23da2c63605c8a32..eeb5375ee7727c956cc357cc8f90b19d1bfe80b9:/SL/DB/ShopOrder.pm diff --git a/SL/DB/ShopOrder.pm b/SL/DB/ShopOrder.pm index 6a53387b5..a43156c1d 100644 --- a/SL/DB/ShopOrder.pm +++ b/SL/DB/ShopOrder.pm @@ -6,10 +6,8 @@ package SL::DB::ShopOrder; 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; @@ -30,13 +28,28 @@ sub convert_to_sales_order { 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{ @@ -55,10 +68,10 @@ sub convert_to_sales_order { 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; @@ -102,6 +115,7 @@ sub convert_to_sales_order { currency_id => $customer->currency_id, transaction_description => $shop->transaction_description, transdate => $transdate, + record_type => SALES_ORDER_TYPE(), ); return $order; }else{ @@ -239,7 +253,9 @@ sub get_customer{ 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; }