X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=7ff850039eea8e1a4aa282c4a09ca1e1cf380688;hb=2f2a0f414c419c559beb3c07340e995eae589c19;hp=3759e5790c161445214107ae37b8772596c8515c;hpb=219d88ab03186a74e5dd474175e49bd74dacf15f;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 3759e5790..7ff850039 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -52,6 +52,7 @@ use SL::IC; use SL::IO; use SL::TransNumber; use SL::DB::Default; +use SL::DB::Draft; use SL::DB::Tax; use SL::DB::TaxZone; use SL::TransNumber; @@ -663,6 +664,13 @@ sub customer_details { 'trans_id' => $form->{customer_id}); map { $form->{"vc_cvar_$_->{name}"} = $_->{value} } @{ $custom_variables }; + if ($form->{cp_id}) { + $custom_variables = CVar->get_custom_variables(dbh => $dbh, + module => 'Contacts', + trans_id => $form->{cp_id}); + $form->{"cp_cvar_$_->{name}"} = $_->{value} for @{ $custom_variables }; + } + $form->{cp_greeting} = GenericTranslations->get('dbh' => $dbh, 'translation_type' => 'greetings::' . ($form->{cp_gender} eq 'f' ? 'female' : 'male'), 'language_id' => $language_id, @@ -1339,9 +1347,6 @@ SQL # need the current dbh to get the not yet committed mtime $form->new_lastmtime('ar', $provided_dbh); - $form->{name} = $form->{customer}; - $form->{name} =~ s/--\Q$form->{customer_id}\E//; - # add shipto if (!$form->{shipto_id}) { $form->add_shipto($dbh, $form->{id}, "AR"); @@ -1405,19 +1410,19 @@ SQL do_query($form, $dbh, $query, @orphaned_ids); } + if ($form->{draft_id}) { + SL::DB::Manager::Draft->delete_all(where => [ id => delete($form->{draft_id}) ]); + } + # safety check datev export if ($::instance_conf->get_datev_check_on_sales_invoice) { - my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : undef; - $transdate ||= DateTime->today; my $datev = SL::DATEV->new( - exporttype => DATEV_ET_BUCHUNGEN, - format => DATEV_FORMAT_KNE, dbh => $dbh, trans_id => $form->{id}, ); - $datev->export; + $datev->generate_datev_data; if ($datev->errors) { die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors; @@ -2132,6 +2137,11 @@ sub get_customer { my $payment_id; # get customer + my $where = ''; + if ($cid) { + $where .= 'AND c.id = ?'; + push @values, $cid; + } $query = qq|SELECT c.id AS customer_id, c.name AS customer, c.discount as customer_discount, c.creditlimit, @@ -2143,8 +2153,7 @@ sub get_customer { FROM customer c LEFT JOIN business b ON (b.id = c.business_id) LEFT JOIN currencies cu ON (c.currency_id=cu.id) - WHERE c.id = ?|; - push @values, $cid; + WHERE 1 = 1 $where|; $ref = selectfirst_hashref_query($form, $dbh, $query, @values); delete $ref->{salesman_id} if !$ref->{salesman_id}; @@ -2203,46 +2212,6 @@ sub get_customer { } $sth->finish; - # setup last accounts used for this customer - if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) { - $query = - qq|SELECT c.id, c.accno, c.description, c.link, c.category - FROM chart c - JOIN acc_trans ac ON (ac.chart_id = c.id) - JOIN ar a ON (a.id = ac.trans_id) - WHERE a.customer_id = ? - AND NOT (c.link LIKE '%_tax%' OR c.link LIKE '%_paid%') - AND a.id IN (SELECT max(a2.id) FROM ar a2 WHERE a2.customer_id = ?)|; - $sth = prepare_execute_query($form, $dbh, $query, $cid, $cid); - - my $i = 0; - while ($ref = $sth->fetchrow_hashref('NAME_lc')) { - if ($ref->{category} eq 'I') { - $i++; - $form->{"AR_amount_$i"} = "$ref->{accno}--$ref->{description}"; - - if ($form->{initial_transdate}) { - my $tax_query = - qq|SELECT tk.tax_id, t.rate - FROM taxkeys tk - LEFT JOIN tax t ON tk.tax_id = t.id - WHERE (tk.chart_id = ?) AND (startdate <= date(?)) - ORDER BY tk.startdate DESC - LIMIT 1|; - my ($tax_id, $rate) = - selectrow_query($form, $dbh, $tax_query, $ref->{id}, - $form->{initial_transdate}); - $form->{"taxchart_$i"} = "${tax_id}--${rate}"; - } - } - if ($ref->{category} eq 'A') { - $form->{ARselected} = $form->{AR_1} = $ref->{accno}; - } - } - $sth->finish; - $form->{rowcount} = $i if ($i && !$form->{type}); - } - $main::lxdebug->leave_sub(); }