X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FShopOrder.pm;h=8ee8d0ec35b354ccd353de23bf2aee0f8c245fb9;hb=14fd87107e86d96894c3f731245172ec04554dd1;hp=684c49b287bc8bc4661236ee798a5211f5de236b;hpb=8f07fac1fa6772d354d2766a060b01244624a0a5;p=kivitendo-erp.git diff --git a/SL/DB/ShopOrder.pm b/SL/DB/ShopOrder.pm index 684c49b28..8ee8d0ec3 100644 --- a/SL/DB/ShopOrder.pm +++ b/SL/DB/ShopOrder.pm @@ -9,6 +9,7 @@ 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; @@ -171,12 +172,23 @@ SQL return $customers; } +sub check_for_open_invoices { + my ($self) = @_; + my $open_invoices = SL::DB::Manager::Invoice->get_all_count( + query => [customer_id => $self->{kivi_customer_id}, + paid => {lt_sql => 'amount'}, + ], + ); + return $open_invoices; +} + sub get_customer{ my ($self, %params) = @_; my $shop = SL::DB::Manager::Shop->find_by(id => $self->shop_id); my $customer_proposals = $self->check_for_existing_customers; my $name = $self->billing_firstname . " " . $self->billing_lastname; my $customer = 0; + my $payment_id = SL::DB::Manager::PaymentTerm->get_first()->id || undef; if(!scalar(@{$customer_proposals})){ my %address = ( 'name' => $name, 'department_1' => $self->billing_company, @@ -195,7 +207,7 @@ sub get_customer{ 'pricegroup_id' => (split '\/',$shop->price_source)[0] eq "pricegroup" ? (split '\/',$shop->price_source)[1] : undef, 'taxzone_id' => $shop->taxzone_id, 'currency' => $::instance_conf->get_currency_id, - #'payment_id' => 7345,# TODO hardcoded + 'payment_id' => $payment_id, ); $customer = SL::DB::Customer->new(%address);