X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=ae3e45b09d49f07b98580ae5fa1fd6f3ac98b107;hb=c7241bf7c547d63999898dee7b5dd486e4d122d3;hp=dd042488bd6299675580cf7c26003ebe6dc493d0;hpb=d557935a1484e5ebbb15f0eabe107d74e192ff0b;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index dd042488b..ae3e45b09 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -369,7 +369,12 @@ sub post_invoice { next if $payments_only; - my $cvars; + CVar->get_non_editable_ic_cvars(form => $form, + dbh => $dbh, + row => $i, + sub_module => 'invoice', + may_converted_from => ['delivery_order_items', 'orderitems', 'invoice']); + if (!$form->{"invoice_id_$i"}) { # there is no persistent id, therefore create one with all necessary constraints my $q_invoice_id = qq|SELECT nextval('invoiceid')|; @@ -380,22 +385,7 @@ sub post_invoice { do_query($form, $dbh, $q_create_invoice_id, conv_i($form->{"invoice_id_$i"}), conv_i($form->{id}), conv_i($position), conv_i($form->{"id_$i"})); $h_invoice_id->finish(); - - # get values for CVars from master data for new items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - trans_id => $form->{"id_$i"}, - ); - } else { - # get values for CVars from custom_variables for existing items - $cvars = CVar->get_custom_variables(dbh => $dbh, - module => 'IC', - sub_module => 'invoice', - trans_id => $form->{"invoice_id_$i"}, - ); } - # map only non-editable CVars to form (editable ones are already there) - map { $form->{"ic_cvar_$_->{name}_$i"} = $_->{value} unless $_->{flag_editable} } @{ $cvars }; # save detail record in invoice table $query = < 'ic_', name_postfix => "_$i", dbh => $dbh); + # link previous items with invoice items See IS.pm (no credit note -> no invoice item) foreach (qw(delivery_order_items orderitems)) { - if ($form->{"converted_from_${_}_id_$i"}) { + if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) { RecordLinks->create_links('dbh' => $dbh, 'mode' => 'ids', 'from_table' => $_, @@ -436,8 +427,8 @@ SQL 'to_table' => 'invoice', 'to_id' => $form->{"invoice_id_$i"}, ); - delete $form->{"converted_from_${_}_id_$i"}; } + delete $form->{"converted_from_${_}_id_$i"}; } } @@ -699,7 +690,7 @@ SQL if ($payments_only) { $query = qq|UPDATE ap SET paid = ? WHERE id = ?|; do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); - + $form->new_lastmtime('ap'); if (!$provided_dbh) { $dbh->commit(); $dbh->disconnect(); @@ -731,7 +722,7 @@ SQL $form->{invnumber}, $form->{ordnumber}, $form->{quonumber}, conv_date($form->{invdate}), conv_date($form->{orddate}), conv_date($form->{quodate}), conv_i($form->{vendor_id}), $amount, $netamount, $form->{paid}, conv_date($form->{duedate}), - '1', $taxzone_id, $form->{notes}, $form->{taxincluded} ? 't' : 'f', + '1', $taxzone_id, $restricter->process($form->{notes}), $form->{taxincluded} ? 't' : 'f', $form->{intnotes}, conv_i($form->{storno_id}), $form->{storno} ? 't' : 'f', conv_i($form->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}), conv_i($form->{delivery_term_id}), conv_i($form->{globalproject_id}), @@ -754,6 +745,7 @@ SQL do_query($form, $dbh, $query, conv_i($form->{id})); } + $form->new_lastmtime('ap'); $form->{name} = $form->{vendor}; $form->{name} =~ s/--\Q$form->{vendor_id}\E//; @@ -809,6 +801,8 @@ SQL # safety check datev export if ($::instance_conf->get_datev_check_on_purchase_invoice) { + # if we need department for kostenstelle in DATEV check + $form->{department} = SL::DB::Manager::Department->find_by(id => $form->{department_id})->description if $form->{department_id}; my $transdate = $::form->{invdate} ? DateTime->from_lxoffice($::form->{invdate}) : undef; $transdate ||= DateTime->today; @@ -816,8 +810,6 @@ SQL exporttype => DATEV_ET_BUCHUNGEN, format => DATEV_FORMAT_KNE, dbh => $dbh, - from => $transdate, - to => $transdate, trans_id => $form->{id}, ); @@ -884,17 +876,20 @@ sub reverse_invoice { #adjust allocated $form->update_balance($dbh, "invoice", "allocated", qq|id = $pthref->{id}|, $qty); - $form->update_balance($dbh, "acc_trans", "amount", - qq| (trans_id = $pthref->{trans_id}) - AND (chart_id = $ref->{expense_accno_id}) - AND (transdate = '$pthref->{transdate}')|, - $amount); + if ( $::instance_conf->get_inventory_system eq 'perpetual' ) { - $form->update_balance($dbh, "acc_trans", "amount", - qq| (trans_id = $pthref->{trans_id}) - AND (chart_id = $ref->{inventory_accno_id}) - AND (transdate = '$pthref->{transdate}')|, - $amount * -1); + $form->update_balance($dbh, "acc_trans", "amount", + qq| (trans_id = $pthref->{trans_id}) + AND (chart_id = $ref->{expense_accno_id}) + AND (transdate = '$pthref->{transdate}')|, + $amount); + + $form->update_balance($dbh, "acc_trans", "amount", + qq| (trans_id = $pthref->{trans_id}) + AND (chart_id = $ref->{inventory_accno_id}) + AND (transdate = '$pthref->{transdate}')|, + $amount * -1); + } last if (($ref->{allocated} -= $qty) <= 0); } @@ -995,12 +990,15 @@ sub retrieve_invoice { $query = qq|SELECT cp_id, invnumber, transdate AS invdate, duedate, orddate, quodate, globalproject_id, ordnumber, quonumber, paid, taxincluded, notes, taxzone_id, storno, gldate, + mtime, itime, intnotes, (SELECT cu.name FROM currencies cu WHERE cu.id=ap.currency_id) AS currency, direct_debit, delivery_term_id FROM ap WHERE id = ?|; $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id})); map { $form->{$_} = $ref->{$_} } keys %$ref; + $form->{mtime} = $form->{itime} if !$form->{mtime}; + $form->{lastmtime} = $form->{mtime}; $form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "sell"); @@ -1140,11 +1138,11 @@ sub get_vendor { my $query = qq|SELECT v.id AS vendor_id, v.name AS vendor, v.discount as vendor_discount, - v.creditlimit, v.terms, v.notes AS intnotes, + v.creditlimit, v.notes AS intnotes, v.email, v.cc, v.bcc, v.language_id, v.payment_id, v.delivery_term_id, v.street, v.zipcode, v.city, v.country, v.taxzone_id, cu.name AS curr, v.direct_debit, $duedate + COALESCE(pt.terms_netto, 0) AS duedate, - b.description AS business + b.discount AS tradediscount, b.description AS business FROM vendor v LEFT JOIN business b ON (b.id = v.business_id) LEFT JOIN payment_terms pt ON (v.payment_id = pt.id) @@ -1347,7 +1345,7 @@ sub retrieve_item { push @{ $ref->{matches} ||= [] }, $::locale->text('Model') . ': ' . join ', ', map { $_->{model} } @{ $mm_by_id{$ref->{id}} }; } - if ($ref->{ean} eq $::form->{"partnumber_$i"}) { + if (($::form->{"partnumber_$i"} ne '') && ($ref->{ean} eq $::form->{"partnumber_$i"})) { push @{ $ref->{matches} ||= [] }, $::locale->text('EAN') . ': ' . $ref->{ean}; } @@ -1656,5 +1654,4 @@ sub get_duedate { return $duedate; } - 1;