X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIS.pm;h=e9bd54d4793d9d73d68016347525e3617649168e;hb=3720cd5e3b013e1b1af311179b383e9f61832baa;hp=3759e5790c161445214107ae37b8772596c8515c;hpb=219d88ab03186a74e5dd474175e49bd74dacf15f;p=kivitendo-erp.git diff --git a/SL/IS.pm b/SL/IS.pm index 3759e5790..e9bd54d47 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -52,10 +52,12 @@ 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; use SL::DB; +use SL::Presenter::Part qw(type_abbreviation classification_abbreviation); use Data::Dumper; use strict; @@ -433,7 +435,7 @@ sub invoice_details { } my $tax_rate = $taxrate * 100; push(@{ $form->{TEMPLATE_ARRAYS}->{tax_rate} }, qq|$tax_rate|); - if ($form->{"assembly_$i"}) { + if ($form->{"part_type_$i"} eq 'assembly') { $sameitem = ""; # get parts and push them onto the stack @@ -663,6 +665,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, @@ -857,9 +866,9 @@ sub _post_invoice { next if $payments_only; - if ($form->{"inventory_accno_$i"} || $form->{"assembly_$i"}) { + if ($form->{"inventory_accno_$i"} || $form->{"part_type_$i"} eq 'assembly') { - if ($form->{"assembly_$i"}) { + if ($form->{"part_type_$i"} eq 'assembly') { # record assembly item as allocated &process_assembly($dbh, $myconfig, $form, $position, $form->{"id_$i"}, $baseqty); @@ -1339,9 +1348,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 +1411,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 +2138,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 +2154,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 +2213,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(); } @@ -2384,8 +2354,8 @@ sub retrieve_item { push @{ $ref->{matches} ||= [] }, $::locale->text('EAN') . ': ' . $ref->{ean}; } - $ref->{type_and_classific} = $::request->presenter->type_abbreviation($ref->{part_type}). - $::request->presenter->classification_abbreviation($ref->{classification_id}); + $ref->{type_and_classific} = type_abbreviation($ref->{part_type}) . + classification_abbreviation($ref->{classification_id}); if (! $ref->{used_for_sale} ) { $has_wrong_pclass = PCLASS_NOTFORSALE ; next; @@ -2467,7 +2437,6 @@ sub retrieve_item { } $ref->{onhand} *= 1; - push @{ $form->{item_list} }, $ref; } $sth->finish;