Revision 27ca3a23
Von Bernd Bleßmann vor fast 3 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
56 | 56 |
__PACKAGE__->run_before('check_auth'); |
57 | 57 |
|
58 | 58 |
__PACKAGE__->run_before('recalc', |
59 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_ap_transaction |
|
59 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
|
|
60 | 60 |
print send_email) ]); |
61 | 61 |
|
62 | 62 |
__PACKAGE__->run_before('get_unalterable_data', |
63 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_ap_transaction |
|
63 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_invoice_for_advance_payment save_and_final_invoice save_and_ap_transaction
|
|
64 | 64 |
print send_email) ]); |
65 | 65 |
|
66 | 66 |
# |
... | ... | |
663 | 663 |
); |
664 | 664 |
} |
665 | 665 |
|
666 |
sub action_save_and_final_invoice { |
|
667 |
my ($self) = @_; |
|
668 |
|
|
669 |
$self->save_and_redirect_to( |
|
670 |
controller => 'oe.pl', |
|
671 |
action => 'oe_invoice_from_order', |
|
672 |
new_invoice_type => 'final_invoice', |
|
673 |
); |
|
674 |
} |
|
675 |
|
|
666 | 676 |
# workflow from sales order to sales quotation |
667 | 677 |
sub action_sales_quotation { |
668 | 678 |
$_[0]->workflow_sales_or_request_for_quotation(); |
... | ... | |
1951 | 1961 |
$has_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr; |
1952 | 1962 |
} |
1953 | 1963 |
|
1964 |
my $has_final_invoice; |
|
1965 |
if ($self->order->id && $self->type eq sales_order_type()) { |
|
1966 |
my $lr = $self->order->linked_records(direction => 'to', to => ['Invoice']); |
|
1967 |
$has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr; |
|
1968 |
} |
|
1969 |
|
|
1954 | 1970 |
for my $bar ($::request->layout->get('actionbar')) { |
1955 | 1971 |
$bar->add( |
1956 | 1972 |
combobox => [ |
... | ... | |
2018 | 2034 |
], |
2019 | 2035 |
], |
2020 | 2036 |
action => [ |
2021 |
t8('Save and Invoice for Advance Payment'),
|
|
2037 |
($has_invoice_for_advance_payment ? t8('Save and Further Invoice for Advance Payment') : t8('Save and Invoice for Advance Payment')),
|
|
2022 | 2038 |
call => [ 'kivi.Order.save', 'save_and_invoice_for_advance_payment', $::instance_conf->get_order_warn_duplicate_parts ], |
2023 | 2039 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
2024 | 2040 |
@req_trans_cost_art, @req_cusordnumber, |
2025 | 2041 |
], |
2026 |
disabled => $has_invoice_for_advance_payment ? t8('This order has already an invoice for advanced payment.')
|
|
2027 |
: undef,
|
|
2042 |
disabled => $has_final_invoice ? t8('This order has already a final invoice.')
|
|
2043 |
: undef, |
|
2028 | 2044 |
only_if => (any { $self->type eq $_ } (sales_order_type())), |
2029 | 2045 |
], |
2046 |
action => [ |
|
2047 |
t8('Save and Final Invoice'), |
|
2048 |
call => [ 'kivi.Order.save', 'save_and_final_invoice', $::instance_conf->get_order_warn_duplicate_parts ], |
|
2049 |
checks => [ 'kivi.Order.check_save_active_periodic_invoices', |
|
2050 |
@req_trans_cost_art, @req_cusordnumber, |
|
2051 |
], |
|
2052 |
disabled => $has_final_invoice ? t8('This order has already a final invoice.') |
|
2053 |
: undef, |
|
2054 |
only_if => (any { $self->type eq $_ } (sales_order_type())) && $has_invoice_for_advance_payment, |
|
2055 |
], |
|
2030 | 2056 |
action => [ |
2031 | 2057 |
t8('Save and AP Transaction'), |
2032 | 2058 |
call => [ 'kivi.Order.save', 'save_and_ap_transaction', $::instance_conf->get_order_warn_duplicate_parts ], |
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; |
bin/mozilla/is.pl | ||
---|---|---|
334 | 334 |
$has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->invoice_type} @$lr; |
335 | 335 |
} |
336 | 336 |
|
337 |
my $is_invoice_for_advance_payment_from_order; |
|
338 |
if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") { |
|
339 |
my $invoice_obj = SL::DB::Invoice->load_cached($form->{id}); |
|
340 |
my $lr = $invoice_obj->linked_records(direction => 'from', from => ['Order']); |
|
341 |
$is_invoice_for_advance_payment_from_order = scalar @$lr >= 1; |
|
342 |
} |
|
343 |
|
|
337 | 344 |
for my $bar ($::request->layout->get('actionbar')) { |
338 | 345 |
$bar->add( |
339 | 346 |
action => [ |
... | ... | |
426 | 433 |
: !$form->{id} ? t8('This invoice has not been posted yet.') |
427 | 434 |
: $has_further_invoice_for_advance_payment ? t8('This invoice has already a further invoice for advanced payment.') |
428 | 435 |
: $has_final_invoice ? t8('This invoice has already a final invoice.') |
436 |
: $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.') |
|
429 | 437 |
: undef, |
430 | 438 |
only_if => $form->{type} eq "invoice_for_advance_payment", |
431 | 439 |
], |
... | ... | |
437 | 445 |
: !$form->{id} ? t8('This invoice has not been posted yet.') |
438 | 446 |
: $has_further_invoice_for_advance_payment ? t8('This invoice has a further invoice for advanced payment.') |
439 | 447 |
: $has_final_invoice ? t8('This invoice has already a final invoice.') |
448 |
: $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.') |
|
440 | 449 |
: undef, |
441 | 450 |
only_if => $form->{type} eq "invoice_for_advance_payment", |
442 | 451 |
], |
... | ... | |
1203 | 1212 |
|
1204 | 1213 |
$main::auth->assert('invoice_edit'); |
1205 | 1214 |
|
1206 |
# search all related invoices for advance payment |
|
1207 |
# |
|
1208 |
# (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice |
|
1209 |
# |
|
1210 |
# we are currently in the last invoice for adv. payment (3 in this example) |
|
1211 | 1215 |
my $related_invoices = IS->_get_invoices_for_advance_payment($form->{id}); |
1212 | 1216 |
|
1213 | 1217 |
delete @{ $form }{qw(printed emailed queued invnumber invdate exchangerate forex deliverydate datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno locked)}; |
bin/mozilla/oe.pl | ||
---|---|---|
1654 | 1654 |
$::dispatcher->end_request; |
1655 | 1655 |
} |
1656 | 1656 |
|
1657 |
_oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed'); |
|
1657 |
_oe_remove_delivered_or_billed_rows(id => $form->{id}, type => 'billed') if $form->{new_invoice_type} ne 'final_invoice';
|
|
1658 | 1658 |
|
1659 | 1659 |
$form->{cp_id} *= 1; |
1660 | 1660 |
|
... | ... | |
1699 | 1699 |
|
1700 | 1700 |
if ( $form->{type} eq 'sales_order' |
1701 | 1701 |
|| $form->{type} eq 'sales_quotation') { |
1702 |
$form->{title} = ($form->{new_invoice_type} eq 'invoice_for_advance_payment') |
|
1703 |
? $locale->text('Add Invoice for Advance Payment')
|
|
1702 |
$form->{title} = ($form->{new_invoice_type} eq 'invoice_for_advance_payment') ? $locale->text('Add Invoice for Advance Payment')
|
|
1703 |
: ($form->{new_invoice_type} eq 'final_invoice') ? $locale->text('Add Final Invoice')
|
|
1704 | 1704 |
: $locale->text('Add Sales Invoice'); |
1705 | 1705 |
$form->{script} = 'is.pl'; |
1706 | 1706 |
$script = "is"; |
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.