Revision 6c0095f1
Von Jan Büren vor mehr als 5 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
627 | 627 |
}; |
628 | 628 |
} |
629 | 629 |
|
630 |
my $payment_type;
|
|
630 |
my ($payment_type, $free_skonto_amount);
|
|
631 | 631 |
if ( defined $::form->{invoice_skontos}->{"$bt_id"} ) { |
632 | 632 |
$payment_type = shift(@{ $::form->{invoice_skontos}->{"$bt_id"} }); |
633 | 633 |
} else { |
634 | 634 |
$payment_type = 'without_skonto'; |
635 |
}; |
|
635 |
} |
|
636 |
|
|
637 |
if ($payment_type eq 'free_skonto') { |
|
638 |
# parse user input > 0 |
|
639 |
if ($::form->parse_amount(\%::myconfig, $::form->{"free_skonto_amount"}->{"$bt_id"}{$invoice->id}) > 0) { |
|
640 |
$free_skonto_amount = $::form->parse_amount(\%::myconfig, $::form->{"free_skonto_amount"}->{"$bt_id"}{$invoice->id}); |
|
641 |
} else { |
|
642 |
return { |
|
643 |
%data, |
|
644 |
result => 'error', |
|
645 |
message => $::locale->text("Free skonto amount has to be a positive number."), |
|
646 |
}; |
|
647 |
} |
|
648 |
} |
|
636 | 649 |
# pay invoice |
637 | 650 |
# TODO rewrite this: really booked amount should be a return value of Payment.pm |
638 | 651 |
# also this controller shouldnt care about how to calc skonto. we simply delegate the |
... | ... | |
648 | 661 |
|
649 | 662 |
# get the right direction for the payment bookings (all amounts < 0 are stornos, credit notes or negative ap) |
650 | 663 |
$amount_for_payment *= -1 if $invoice->amount < 0; |
664 |
$free_skonto_amount *= -1 if ($free_skonto_amount && $invoice->amount < 0); |
|
651 | 665 |
# get the right direction for the bank transaction |
652 | 666 |
$amount_for_booking *= $sign; |
653 | 667 |
|
... | ... | |
655 | 669 |
|
656 | 670 |
# ... and then pay the invoice |
657 | 671 |
my @acc_ids = $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id, |
658 |
trans_id => $invoice->id, |
|
659 |
amount => $amount_for_payment, |
|
660 |
payment_type => $payment_type, |
|
661 |
source => $source, |
|
662 |
memo => $memo, |
|
663 |
transdate => $bank_transaction->valutadate->to_kivitendo); |
|
672 |
trans_id => $invoice->id, |
|
673 |
amount => $amount_for_payment, |
|
674 |
payment_type => $payment_type, |
|
675 |
source => $source, |
|
676 |
memo => $memo, |
|
677 |
skonto_amount => $free_skonto_amount, |
|
678 |
transdate => $bank_transaction->valutadate->to_kivitendo); |
|
664 | 679 |
# ... and record the origin via BankTransactionAccTrans |
665 | 680 |
if (scalar(@acc_ids) < 2) { |
666 | 681 |
return { |
SL/DB/Helper/Payment.pm | ||
---|---|---|
461 | 461 |
|
462 | 462 |
sub amount_less_skonto { |
463 | 463 |
# amount that has to be paid if skonto applies, always return positive rounded values |
464 |
# no, rare case, but credit_notes and negative ap have negative amounts |
|
465 |
# and therefore this comment may be misguiding |
|
464 | 466 |
# the result is rounded so we can directly compare it with the user input |
465 | 467 |
my $self = shift; |
466 | 468 |
|
... | ... | |
650 | 652 |
|
651 | 653 |
|
652 | 654 |
# CAVEAT template code expects with_skonto_pt at position 1 for visual help |
655 |
# due to skonto_charts, we cannot offer skonto for credit notes and neg ap |
|
656 |
my $skontoable = $self->amount > 0 ? 1 : 0; |
|
653 | 657 |
my @options; |
654 | 658 |
if(!$self->skonto_date) { |
655 | 659 |
push(@options, { payment_type => 'without_skonto', display => t8('without skonto'), selected => 1 }); |
656 | 660 |
# wrong call to presenter or not implemented? disabled option is ignored |
657 | 661 |
# push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), disabled => 1 }); |
658 |
push(@options, { payment_type => 'free_skonto', display => t8('free skonto') }); |
|
662 |
push(@options, { payment_type => 'free_skonto', display => t8('free skonto') }) if $skontoable;
|
|
659 | 663 |
return @options; |
660 | 664 |
} |
661 | 665 |
# valid skonto date, check if skonto is preferred |
662 | 666 |
my $bt = SL::DB::BankTransaction->new(id => $bt_id)->load; |
663 | 667 |
if ($self->skonto_date && $self->within_skonto_period($bt->transdate)) { |
664 | 668 |
push(@options, { payment_type => 'without_skonto', display => t8('without skonto') }); |
665 |
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), selected => 1 }); |
|
669 |
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), selected => 1 }) if $skontoable;
|
|
666 | 670 |
} else { |
667 | 671 |
push(@options, { payment_type => 'without_skonto', display => t8('without skonto') , selected => 1 }); |
668 |
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt')}); |
|
672 |
push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt')}) if $skontoable;
|
|
669 | 673 |
} |
670 |
push(@options, { payment_type => 'free_skonto', display => t8('free skonto') }); |
|
674 |
push(@options, { payment_type => 'free_skonto', display => t8('free skonto') }) if $skontoable;
|
|
671 | 675 |
return @options; |
672 | 676 |
} |
673 | 677 |
|
... | ... | |
783 | 787 |
The params C<transdate> and C<chart_id> are mandantory. |
784 | 788 |
If the default payment ('without_skonto') is used the param amount is also |
785 | 789 |
mandantory. |
786 |
If the payment type ('free_skonto') is used the number param skonto_amount |
|
787 |
is as well mandantory and has to be lower than the currently open invoice amount. |
|
790 |
If the payment type ('free_skonto') is used the number params skonto_amount and amount |
|
791 |
are as well mandantory and need to be positive. Furthermore the skonto amount has |
|
792 |
to be lower than the payment or open invoice amount. |
|
788 | 793 |
|
789 | 794 |
Transdate can either be a date object or a date string. |
790 | 795 |
Chart_id is the id of the payment booking chart. |
... | ... | |
1131 | 1136 |
when looking at open amount, maybe consider that there may already be queued |
1132 | 1137 |
amounts in SEPA Export |
1133 | 1138 |
|
1139 |
=item * C<skonto_charts> |
|
1140 |
|
|
1141 |
Cannot handle negative skonto amounts, will always calculate the skonto amount |
|
1142 |
for credit notes or negative ap transactions with a positive sign. |
|
1143 |
|
|
1144 |
|
|
1134 | 1145 |
=back |
1135 | 1146 |
|
1136 | 1147 |
=head1 AUTHOR |
js/kivi.BankTransaction.js | ||
---|---|---|
140 | 140 |
} |
141 | 141 |
}); |
142 | 142 |
}; |
143 |
ns.update_skonto = function(caller, bt_id, prop_id, formatted_amount_with_skonto_pt) { |
|
144 |
if (caller.value === 'free_skonto') { |
|
145 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val(""); |
|
146 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', false); |
|
147 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).focus(); |
|
148 |
} |
|
149 |
if (caller.value === 'without_skonto') { |
|
150 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val(kivi.format_amount(0,2)); |
|
151 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true); |
|
152 |
} |
|
153 |
if (caller.value === 'with_skonto_pt') { |
|
154 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val(formatted_amount_with_skonto_pt); |
|
155 |
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true); |
|
156 |
} |
|
157 |
}; |
|
158 |
|
|
143 | 159 |
}); |
templates/webpages/bank_transactions/_payment_suggestion.html | ||
---|---|---|
2 | 2 |
<span id="[% HTML.escape(bt_id) %].[% HTML.escape(invoice.id) %]" data-invoice-amount="[% HTML.escape(invoice.open_amount * 1) %]"> |
3 | 3 |
[% P.hidden_tag("invoice_ids." _ bt_id _ "[]", invoice.id) %] |
4 | 4 |
[% SELECT_OPTIONS = invoice.get_payment_select_options_for_bank_transaction(bt_id) %] |
5 |
[% formatted_skonto_amount_selected = SELECT_OPTIONS.1.selected ? LxERP.format_amount(invoice.skonto_amount, 2) : LxERP.format_amount(0, 2) %] |
|
6 |
[% formatted_skonto_amount = LxERP.format_amount(invoice.skonto_amount, 2) %] |
|
5 | 7 |
[% LxERP.t8("Invno.") %]: [% HTML.escape(invoice.invnumber) %]</br> |
6 | 8 |
[% LxERP.t8("Open amount") %]: [% LxERP.format_amount(invoice.open_amount, 2) %]</br> |
7 |
[% P.select_tag("invoice_skontos." _ bt_id _ "[]", SELECT_OPTIONS, value_key="payment_type", title_key="display") %] |
|
9 |
[% P.select_tag("invoice_skontos." _ bt_id _ "[]", SELECT_OPTIONS, value_key="payment_type", title_key="display", onChange="kivi.BankTransaction.update_skonto(this, " _ bt_id _ ", " _ invoice.id _ ", '$formatted_skonto_amount')" ) %]</br> |
|
10 |
[% LxERP.t8("Skonto amount") %]: [% P.input_tag("free_skonto_amount." _ bt_id _ "." _ invoice.id _ "", "$formatted_skonto_amount_selected", default=0, style=style, disabled=1, size=4, class='numeric') %] |
|
8 | 11 |
[% P.link_tag("#", "x", onclick="kivi.BankTransaction.delete_invoice(" _ bt_id _ "," _ invoice.id _ ")") %] |
9 | 12 |
</span> |
Auch abrufbar als: Unified diff
Kontoauszug verbuchen: Neuen Skonto-Typ
Eingabe eines freien Skonto-Betrags in der Maske aktiv.
Ferner Anzeigen des Skonto-Betrags bei with_skonto_pt, damit
der Anwender besser visuell unterstützt wird.