From 34420ddb07d6ebea006aa96f131aaa050a7037bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Tue, 24 Feb 2015 14:12:34 +0100 Subject: [PATCH] =?utf8?q?Verkn=C3=BCpfung=20von=20Einzelpositionen=20auch?= =?utf8?q?=20bei=20periodisch=20erzeugten=20Rechnungen=20(Auftrag=20->=20R?= =?utf8?q?echnung)=20F=C3=BCr=20InvoiceItem=20in=20Invoice=20ein=20convert?= =?utf8?q?ed=5Ffrom=5F*=5Fid=20hinzugef=C3=BCgt=20wie=20bei=20der=20Verkn?= =?utf8?q?=C3=BCpfung=20von=20Auftrag=20zu=20Rechnung,=20bzw.=20Liefersche?= =?utf8?q?in=20zu=20Rechnung.=20Letzterer=20Weg=20wird=20aktuell=20bei=20O?= =?utf8?q?bjekten=20noch=20nicht=20benutzt.=20Ferner=20einen=20R=C3=BCckga?= =?utf8?q?bewert=20von=20create=5Flinks=20(RecordLinks)=20etwas=20verbesse?= =?utf8?q?rt=20(undef=20bei=20nicht=20=20erfolgtem=20Anlegen).=20Offen:=20?= =?utf8?q?Implementierung=20der=20Verkn=C3=BCpfung=20von=20DeliveryOrderIt?= =?utf8?q?em-Objekten=20mit=20InvoiceItem-Objekten.=20Diese=20werden=20akt?= =?utf8?q?uell=20nicht=20benutzt=20und=20betrifft=20auch=20nicht=20periodi?= =?utf8?q?sche=20Rechnungen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/BackgroundJob/CreatePeriodicInvoices.pm | 19 +++++++++++++++- SL/DB/Helper/LinkedRecords.pm | 2 +- SL/DB/Invoice.pm | 25 ++++++++++++---------- SL/RecordLinks.pm | 2 +- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index ce8957770..5055083ac 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -143,6 +143,8 @@ sub _replace_vars { } sub _create_periodic_invoice { + $main::lxdebug->enter_sub(); + my $self = shift; my $config = shift; my $period_start_date = shift; @@ -188,6 +190,21 @@ sub _create_periodic_invoice { $order->link_to_record($invoice); + foreach my $item (@{ $invoice->items }) { + foreach (qw(orderitems)) { # expand if needed (delivery_order_items) + if ($item->{"converted_from_${_}_id"}) { + die unless $item->{id}; + RecordLinks->create_links('mode' => 'ids', + 'from_table' => $_, + 'from_ids' => $item->{"converted_from_${_}_id"}, + 'to_table' => 'invoice', + 'to_id' => $item->{id}, + ) || die; + delete $item->{"converted_from_${_}_id"}; + } + } + } + SL::DB::PeriodicInvoice->new(config_id => $config->id, ar_id => $invoice->id, period_start_date => $period_start_date) @@ -198,7 +215,7 @@ sub _create_periodic_invoice { $::lxdebug->message(LXDebug->WARN(), "_create_invoice failed: " . join("\n", (split(/\n/, $self->{db_obj}->db->error))[0..2])); return undef; } - + $main::lxdebug->leave_sub(); return $invoice; } diff --git a/SL/DB/Helper/LinkedRecords.pm b/SL/DB/Helper/LinkedRecords.pm index bb21ecf27..115198124 100644 --- a/SL/DB/Helper/LinkedRecords.pm +++ b/SL/DB/Helper/LinkedRecords.pm @@ -384,7 +384,7 @@ array reference. Examples: If you only need invoices created directly from an order C<$order> (no -delivery orders inbetween) then the call could look like this: +delivery orders in between) then the call could look like this: my $invoices = $order->linked_records( direction => 'to', diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index e8b49c46f..a64ef2fb3 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -193,17 +193,20 @@ sub new_from { $item_parents{$source_item_id} ||= $source_item->$item_parent_column; my $item_parent = $item_parents{$source_item_id}; - - SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } - qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit - base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns), - deliverydate => $source_item->reqdate, - fxsellprice => $source_item->sellprice, - custom_variables => \@custom_variables, - ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, - donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', - ); - + my $current_invoice_item = + SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } + qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit + base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns), + deliverydate => $source_item->reqdate, + fxsellprice => $source_item->sellprice, + custom_variables => \@custom_variables, + ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, + donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', + ); + + $current_invoice_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; + $current_invoice_item->{"converted_from_delivery_order_items_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::DeliveryOrder'; + $current_invoice_item; } @{ $items }; @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty}; diff --git a/SL/RecordLinks.pm b/SL/RecordLinks.pm index 77086ba70..0bd62fa31 100644 --- a/SL/RecordLinks.pm +++ b/SL/RecordLinks.pm @@ -48,7 +48,7 @@ sub create_links { if (!scalar @links) { $main::lxdebug->leave_sub(); - return; + return undef; } my $myconfig = \%main::myconfig; -- 2.20.1