X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDB%2FShopOrder.pm;h=ae5d8568f72a730b955f02a72c4c8c34aa726ee3;hb=670a6e6cb58ccaef212150406b66a955295fe074;hp=4e125fbc9f3bdf4f962e89e72910ea5b9aae10d2;hpb=51504ef44a8f49be8baa983e8a37c301acb9a937;p=kivitendo-erp.git diff --git a/SL/DB/ShopOrder.pm b/SL/DB/ShopOrder.pm index 4e125fbc9..ae5d8568f 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; @@ -95,7 +96,7 @@ sub convert_to_sales_order { intnotes => $customer->notes, salesman_id => $employee->id, taxincluded => $self->tax_included, - payment_id => $customer->payment_id, + payment_id => $self->payment_id, taxzone_id => $customer->taxzone_id, currency_id => $customer->currency_id, transaction_description => $shop->transaction_description, @@ -122,7 +123,7 @@ sub check_for_existing_customers { my $zipcode = $self->billing_street ne '' ? $self->billing_zipcode : ''; my $email = $self->billing_street ne '' ? $self->billing_email : ''; - if($self->check_trgm) { + if(check_trgm($::form->get_standard_dbh())) { # Fuzzysearch for street to find e.g. "Dorfstrasse - Dorfstr. - Dorfstraße" my $fs_query = <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 $default_payment = SL::DB::Manager::PaymentTerm->get_first(); + my $payment_id = $default_payment ? $default_payment->id : undef; if(!scalar(@{$customer_proposals})){ my %address = ( 'name' => $name, 'department_1' => $self->billing_company, @@ -195,7 +208,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); @@ -235,17 +248,6 @@ sub compare_to { return $result || ($self->id <=> $other->id); } -sub check_trgm { - my ( $self ) = @_; - - my $dbh = $::form->get_standard_dbh(); - my $sql = "SELECT installed_version FROM pg_available_extensions WHERE name = 'pg_trgm'"; - my @version = selectall_hashref_query($::form, $dbh, $sql); - - return 1 if($version[0]->{installed_version}); - return 0; -} - sub has_differing_delivery_address { my ($self) = @_; ($self->billing_firstname // '') ne ($self->delivery_firstname // '') || @@ -294,10 +296,6 @@ When it is 0 get customer creates a new customer object of the shop order billin =item C -=item C - -Checks if the postgresextension pg_trgm is installed and return 0 or 1. - =back =head1 TODO