Revision 34420ddb
Von Jan Büren vor fast 10 Jahren hinzugefügt
SL/BackgroundJob/CreatePeriodicInvoices.pm | ||
---|---|---|
143 | 143 |
} |
144 | 144 |
|
145 | 145 |
sub _create_periodic_invoice { |
146 |
$main::lxdebug->enter_sub(); |
|
147 |
|
|
146 | 148 |
my $self = shift; |
147 | 149 |
my $config = shift; |
148 | 150 |
my $period_start_date = shift; |
... | ... | |
188 | 190 |
|
189 | 191 |
$order->link_to_record($invoice); |
190 | 192 |
|
193 |
foreach my $item (@{ $invoice->items }) { |
|
194 |
foreach (qw(orderitems)) { # expand if needed (delivery_order_items) |
|
195 |
if ($item->{"converted_from_${_}_id"}) { |
|
196 |
die unless $item->{id}; |
|
197 |
RecordLinks->create_links('mode' => 'ids', |
|
198 |
'from_table' => $_, |
|
199 |
'from_ids' => $item->{"converted_from_${_}_id"}, |
|
200 |
'to_table' => 'invoice', |
|
201 |
'to_id' => $item->{id}, |
|
202 |
) || die; |
|
203 |
delete $item->{"converted_from_${_}_id"}; |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
191 | 208 |
SL::DB::PeriodicInvoice->new(config_id => $config->id, |
192 | 209 |
ar_id => $invoice->id, |
193 | 210 |
period_start_date => $period_start_date) |
... | ... | |
198 | 215 |
$::lxdebug->message(LXDebug->WARN(), "_create_invoice failed: " . join("\n", (split(/\n/, $self->{db_obj}->db->error))[0..2])); |
199 | 216 |
return undef; |
200 | 217 |
} |
201 |
|
|
218 |
$main::lxdebug->leave_sub(); |
|
202 | 219 |
return $invoice; |
203 | 220 |
} |
204 | 221 |
|
SL/DB/Helper/LinkedRecords.pm | ||
---|---|---|
384 | 384 |
Examples: |
385 | 385 |
|
386 | 386 |
If you only need invoices created directly from an order C<$order> (no |
387 |
delivery orders inbetween) then the call could look like this: |
|
387 |
delivery orders in between) then the call could look like this:
|
|
388 | 388 |
|
389 | 389 |
my $invoices = $order->linked_records( |
390 | 390 |
direction => 'to', |
SL/DB/Invoice.pm | ||
---|---|---|
193 | 193 |
|
194 | 194 |
$item_parents{$source_item_id} ||= $source_item->$item_parent_column; |
195 | 195 |
my $item_parent = $item_parents{$source_item_id}; |
196 |
|
|
197 |
SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } |
|
198 |
qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit |
|
199 |
base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns), |
|
200 |
deliverydate => $source_item->reqdate, |
|
201 |
fxsellprice => $source_item->sellprice, |
|
202 |
custom_variables => \@custom_variables, |
|
203 |
ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, |
|
204 |
donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', |
|
205 |
); |
|
206 |
|
|
196 |
my $current_invoice_item = |
|
197 |
SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } |
|
198 |
qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit |
|
199 |
base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns), |
|
200 |
deliverydate => $source_item->reqdate, |
|
201 |
fxsellprice => $source_item->sellprice, |
|
202 |
custom_variables => \@custom_variables, |
|
203 |
ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, |
|
204 |
donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', |
|
205 |
); |
|
206 |
|
|
207 |
$current_invoice_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; |
|
208 |
$current_invoice_item->{"converted_from_delivery_order_items_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::DeliveryOrder'; |
|
209 |
$current_invoice_item; |
|
207 | 210 |
} @{ $items }; |
208 | 211 |
|
209 | 212 |
@items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty}; |
SL/RecordLinks.pm | ||
---|---|---|
48 | 48 |
|
49 | 49 |
if (!scalar @links) { |
50 | 50 |
$main::lxdebug->leave_sub(); |
51 |
return; |
|
51 |
return undef;
|
|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
my $myconfig = \%main::myconfig; |
Auch abrufbar als: Unified diff
Verknüpfung von Einzelpositionen auch bei periodisch erzeugten Rechnungen (Auftrag -> Rechnung)
Für InvoiceItem in Invoice ein converted_from_*_id hinzugefügt wie bei der Verknüpfung von Auftrag zu
Rechnung, bzw. Lieferschein zu Rechnung. Letzterer Weg wird aktuell bei Objekten noch nicht
benutzt. Ferner einen Rückgabewert von create_links (RecordLinks) etwas verbessert (undef bei nicht
erfolgtem Anlegen).
Offen: Implementierung der Verknüpfung von DeliveryOrderItem-Objekten mit InvoiceItem-Objekten.
Diese werden aktuell nicht benutzt und betrifft auch nicht periodische Rechnungen.