Revision 27ca3a23
Von Bernd Bleßmann vor fast 3 Jahren hinzugefügt
SL/IS.pm | ||
---|---|---|
578 | 578 |
$form->{username} = $myconfig->{name}; |
579 | 579 |
$form->{$_} = $form->format_amount($myconfig, $form->{$_}, 2) for @separate_totals; |
580 | 580 |
|
581 |
foreach my $invoice_for_advance_payment (@{$self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id})}) { |
|
581 |
my $id_for_iap = $form->{convert_from_oe_ids} || $form->{convert_from_ar_ids} || $form->{id}; |
|
582 |
my $from_order = !!$form->{convert_from_oe_ids}; |
|
583 |
foreach my $invoice_for_advance_payment (@{$self->_get_invoices_for_advance_payment($id_for_iap, $from_order)}) { |
|
582 | 584 |
# Collect VAT of invoices for advance payment. |
583 | 585 |
# Set sellprices to fxsellprices for items, because |
584 | 586 |
# the PriceTaxCalculator sets fxsellprice from sellprice before calculating. |
... | ... | |
1090 | 1092 |
|
1091 | 1093 |
my $iap_amounts; |
1092 | 1094 |
if ($form->{type} eq 'final_invoice') { |
1093 |
my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id}); |
|
1095 |
my $id_for_iap = $form->{convert_from_oe_ids} || $form->{convert_from_ar_ids} || $form->{id}; |
|
1096 |
my $from_order = !!$form->{convert_from_oe_ids}; |
|
1097 |
my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($id_for_iap, $from_order); |
|
1094 | 1098 |
if (scalar @$invoices_for_advance_payment > 0) { |
1095 | 1099 |
# reverse booking for invoices for advance payment |
1096 | 1100 |
foreach my $invoice_for_advance_payment (@$invoices_for_advance_payment) { |
... | ... | |
1587 | 1591 |
} |
1588 | 1592 |
|
1589 | 1593 |
sub _get_invoices_for_advance_payment { |
1590 |
my ($self, $id) = @_; |
|
1594 |
my ($self, $id, $id_is_from_order) = @_;
|
|
1591 | 1595 |
|
1592 | 1596 |
return [] if !$id; |
1593 | 1597 |
|
1594 |
my $invoice_obj = SL::DB::Invoice->new(id => $id*1)->load; |
|
1595 |
my $links = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1); |
|
1598 |
# Search all related invoices for advance payment. |
|
1599 |
# Case 1: |
|
1600 |
# (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice |
|
1601 |
# |
|
1602 |
# Case 2: |
|
1603 |
# order -> invoice for adv. payment 1 |
|
1604 |
# | |`-> invoice for adv. payment 2 |
|
1605 |
# | `--> invoice for adv. payment 3 |
|
1606 |
# `----> final invoice |
|
1607 |
# |
|
1608 |
# The id is currently that from the last invoice for adv. payment (3 in this example), |
|
1609 |
# that from the final invoice or that from the order. |
|
1610 |
|
|
1611 |
my $invoice_obj; |
|
1612 |
my $order_obj; |
|
1613 |
my $links; |
|
1614 |
|
|
1615 |
if (!$id_is_from_order) { |
|
1616 |
$invoice_obj = SL::DB::Invoice->load_cached($id*1); |
|
1617 |
$links = $invoice_obj->linked_records(direction => 'from', from => ['Order']); |
|
1618 |
$order_obj = $links->[0]; |
|
1619 |
} else { |
|
1620 |
$order_obj = SL::DB::Order->load_cached($id*1); |
|
1621 |
} |
|
1622 |
|
|
1623 |
if ($order_obj) { |
|
1624 |
$links = $order_obj ->linked_records(direction => 'to', to => ['Invoice']); |
|
1625 |
} else { |
|
1626 |
$links = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1); |
|
1627 |
} |
|
1628 |
|
|
1596 | 1629 |
my @related_invoices = grep {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$links; |
1597 | 1630 |
|
1598 |
push @related_invoices, $invoice_obj if "invoice_for_advance_payment" eq $invoice_obj->type; |
|
1631 |
push @related_invoices, $invoice_obj if !$order_obj && "invoice_for_advance_payment" eq $invoice_obj->type;
|
|
1599 | 1632 |
|
1600 | 1633 |
return \@related_invoices; |
1601 | 1634 |
} |
... | ... | |
2109 | 2142 |
|
2110 | 2143 |
# if we delete a final invoice, the reverse bookings for the clearing account in the invoice for advance payment |
2111 | 2144 |
# must be deleted as well |
2112 |
my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id});
|
|
2145 |
my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{id}); |
|
2113 | 2146 |
|
2114 | 2147 |
# Todo: allow only if invoice for advance payment is not paid. |
2115 | 2148 |
# die if any { $_->paid } for @$invoices_for_advance_payment; |
Auch abrufbar als: Unified diff
Anzahlungs-Rg.: Workflow vom Auftrag: alle Anzahlugns-Rg. und Schluss-Rg.
Wird der Workflow vom Auftrag aus begonnen, so werden alle Anzahlungs- und
die Schlussrechnung vom Auftrag aus gemacht.
Der Einstieg über eine Anzahlungs-Rg. und dann der Workflow
"weitere Anzahlungs-Rg." (...) und hieraus Schluss-Rg. bleibt bestehen.