X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FIR.pm;h=5b093422175de63db6a9ace931e9e16185e2215d;hb=64c39b744b9fba960b32315ac7ea36477c85e8a5;hp=0da055bbb16c6343f3bcdc52cdd2623c99351992;hpb=cd51d3e231d49544b3fb4e6705548cdc9d189951;p=kivitendo-erp.git diff --git a/SL/IR.pm b/SL/IR.pm index 0da055bbb..5b0934221 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -35,8 +35,10 @@ package IR; use SL::AM; +use SL::ARAP; use SL::Common; use SL::DBUtils; +use SL::DO; use SL::MoreCommon; use List::Util qw(min); @@ -342,7 +344,7 @@ sub post_invoice { $expensediff += $paiddiff; ######## this only applies to tax included - + $form->{amount}{ $form->{id} }{$lastinventoryaccno} -= $invoicediff if $lastinventoryaccno; $form->{amount}{ $form->{id} }{$lastexpenseaccno} -= $expensediff if $lastexpenseaccno; @@ -363,11 +365,11 @@ sub post_invoice { $form->{amount}{ $form->{id} }{ $form->{AP} } = $netamount + $tax; - + $form->{paid} = $form->round_amount($form->{paid} * $form->{exchangerate} + $paiddiff, 2) if $form->{paid} != 0; # update exchangerate - + $form->update_exchangerate($dbh, $form->{currency}, $form->{invdate}, 0, $form->{exchangerate}) if ($form->{currency} ne $defaultcurrency) && !$exchangerate; @@ -396,7 +398,7 @@ sub post_invoice { } # force AP entry if 0 - + $form->{amount}{ $form->{id} }{ $form->{AP} } = $form->{paid} if $form->{amount}{$form->{id}}{$form->{AP}} == 0; # record payments and offsetting AP @@ -498,7 +500,7 @@ sub post_invoice { netamount = ?, paid = ?, duedate = ?, datepaid = ?, invoice = ?, taxzone_id = ?, notes = ?, taxincluded = ?, intnotes = ?, curr = ?, storno_id = ?, storno = ?, - cp_id = ?, employee_id = ?, department_id = ?, + cp_id = ?, employee_id = ?, department_id = ?, globalproject_id = ? WHERE id = ?|; @values = ( @@ -507,7 +509,7 @@ sub post_invoice { $netamount, $form->{paid}, conv_date($form->{duedate}), $form->{paid} ? conv_date($form->{datepaid}) : undef, '1', $taxzone_id, $form->{notes}, $form->{taxincluded} ? 't' : 'f', $form->{intnotes}, $form->{currency}, 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->{cp_id}), conv_i($form->{employee_id}), conv_i($form->{department_id}), conv_i($form->{globalproject_id}), conv_i($form->{id}) ); @@ -521,7 +523,7 @@ sub post_invoice { do_query($form, $dbh, $query, conv_i($form->{storno_id})); $query = qq!UPDATE ap SET intnotes = ? || intnotes WHERE id = ?!; - do_query($form, $dbh, $query, 'Rechnung storniert am $form->{invdate} ', conv_i($form->{storno_id})); + do_query($form, $dbh, $query, "Rechnung storniert am $form->{invdate} ", conv_i($form->{storno_id})); $query = qq|UPDATE ap SET paid = amount WHERE id = ?|; do_query($form, $dbh, $query, conv_i($form->{id})); @@ -538,8 +540,36 @@ sub post_invoice { Common::webdav_folder($form) if ($main::webdav); - my $rc = 1; + # Link this record to the records it was created from. + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'oe', + 'from_ids' => $form->{convert_from_oe_ids}, + 'to_table' => 'ap', + 'to_id' => $form->{id}, + ); + delete $form->{convert_from_oe_ids}; + + my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids}; + if (scalar @convert_from_do_ids) { + DO->close_orders('dbh' => $dbh, + 'ids' => \@convert_from_do_ids); + + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'delivery_orders', + 'from_ids' => \@convert_from_do_ids, + 'to_table' => 'ap', + 'to_id' => $form->{id}, + ); + } + delete $form->{convert_from_do_ids}; + + ARAP->close_orders_if_billed('dbh' => $dbh, + 'arap_id' => $form->{id}, + 'table' => 'ap',); + my $rc = 1; if (!$provided_dbh) { $rc = $dbh->commit(); $dbh->disconnect(); @@ -836,7 +866,7 @@ sub get_vendor { } my $query = qq|SELECT - v.name AS vendor, v.creditlimit, v.terms, v.notes AS intnotes, + v.id AS vendor_id, v.name AS vendor, v.creditlimit, v.terms, v.notes AS intnotes, v.email, v.cc, v.bcc, v.language_id, v.payment_id, v.street, v.zipcode, v.city, v.country, v.taxzone_id, $duedate + COALESCE(pt.terms_netto, 0) AS duedate, @@ -940,7 +970,12 @@ sub retrieve_item { $where .= " AND lower(${table_column}) LIKE lower(?)"; push @values, '%' . $form->{"${field}_${i}"} . '%'; } - + #Es soll auch nach EAN gesucht werden, ohne Einschränkung durch Beschreibung + if ($form->{"partnumber_$i"} && !$form->{"description_$i"}) { + $where .= qq| OR (NOT p.obsolete = '1' AND p.ean = ? )|; + push @values, $form->{"partnumber_$i"}; + } + if ($form->{"description_$i"}) { $where .= " ORDER BY p.description"; } else { @@ -1253,4 +1288,42 @@ sub post_payment { return $rc; } +sub get_duedate { + $main::lxdebug->enter_sub(); + + my $self = shift; + my %params = @_; + + if (!$params{vendor_id} || !$params{invdate}) { + $main::lxdebug->leave_sub(); + return $params{default}; + } + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $query = qq|SELECT ?::date + pt.terms_netto + FROM vendor v + LEFT JOIN payment_terms pt ON (pt.id = v.payment_id) + WHERE v.id = ?|; + + my ($sth, $duedate); + + if (($sth = $dbh->prepare($query)) && $sth->execute($params{invdate}, conv_i($params{vendor_id}))) { + ($duedate) = $sth->fetchrow_array(); + $sth->finish(); + } else { + $dbh->rollback(); + } + + $duedate ||= $params{default}; + + $main::lxdebug->leave_sub(); + + return $duedate; +} + + 1;