Revision 24fd073e
Von Jan Büren vor fast 2 Jahren hinzugefügt
SL/DB/Helper/Payment.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use parent qw(Exporter); |
6 | 6 |
our @EXPORT = qw(pay_invoice); |
7 |
our @EXPORT_OK = qw(skonto_date amount_less_skonto within_skonto_period percent_skonto reference_account reference_amount open_amount open_percent remaining_skonto_days skonto_amount check_skonto_configuration valid_skonto_amount get_payment_suggestions validate_payment_type open_sepa_transfer_amount get_payment_select_options_for_bank_transaction exchangerate forex _skonto_charts_and_tax_correction);
|
|
7 |
our @EXPORT_OK = qw(skonto_date amount_less_skonto within_skonto_period percent_skonto reference_account open_amount skonto_amount check_skonto_configuration valid_skonto_amount get_payment_suggestions validate_payment_type open_sepa_transfer_amount get_payment_select_options_for_bank_transaction exchangerate forex _skonto_charts_and_tax_correction);
|
|
8 | 8 |
our %EXPORT_TAGS = ( |
9 | 9 |
"ALL" => [@EXPORT, @EXPORT_OK], |
10 | 10 |
); |
... | ... | |
422 | 422 |
return $reference_account; |
423 | 423 |
}; |
424 | 424 |
|
425 |
sub reference_amount { |
|
426 |
my $self = shift; |
|
427 |
|
|
428 |
my $is_sales = ref($self) eq 'SL::DB::Invoice'; |
|
429 |
|
|
430 |
require SL::DB::Manager::AccTransaction; |
|
431 |
|
|
432 |
my $link_filter = $is_sales ? 'AR' : 'AP'; |
|
433 |
|
|
434 |
my $acc_trans = SL::DB::Manager::AccTransaction->find_by( |
|
435 |
trans_id => $self->id, |
|
436 |
SL::DB::Manager::AccTransaction->chart_link_filter("$link_filter") |
|
437 |
); |
|
438 |
|
|
439 |
return undef unless ref $acc_trans; |
|
440 |
|
|
441 |
# this should be the same as $self->amount |
|
442 |
return $acc_trans->amount; |
|
443 |
}; |
|
444 |
|
|
445 |
|
|
446 | 425 |
sub open_amount { |
447 | 426 |
my $self = shift; |
448 | 427 |
|
... | ... | |
454 | 433 |
return ($self->amount // 0) - ($self->paid // 0); |
455 | 434 |
}; |
456 | 435 |
|
457 |
sub open_percent { |
|
458 |
my $self = shift; |
|
459 |
|
|
460 |
return 0 if $self->amount == 0; |
|
461 |
my $open_percent; |
|
462 |
if ( $self->open_amount < 0 ) { |
|
463 |
# overpaid, currently treated identically |
|
464 |
$open_percent = $self->open_amount * 100 / $self->amount; |
|
465 |
} else { |
|
466 |
$open_percent = $self->open_amount * 100 / $self->amount; |
|
467 |
}; |
|
468 |
|
|
469 |
return _round($open_percent) || 0; |
|
470 |
}; |
|
471 |
|
|
472 | 436 |
sub skonto_amount { |
473 | 437 |
my $self = shift; |
474 | 438 |
|
475 | 439 |
return $self->amount - $self->amount_less_skonto; |
476 | 440 |
}; |
477 | 441 |
|
478 |
sub remaining_skonto_days { |
|
479 |
my $self = shift; |
|
480 |
|
|
481 |
return undef unless ref $self->skonto_date; |
|
482 |
|
|
483 |
my $dur = DateTime::Duration->new($self->skonto_date - DateTime->today); |
|
484 |
return $dur->delta_days(); |
|
485 |
|
|
486 |
}; |
|
487 |
|
|
488 | 442 |
sub percent_skonto { |
489 | 443 |
my $self = shift; |
490 | 444 |
|
... | ... | |
542 | 496 |
|
543 | 497 |
sub open_sepa_transfer_amount { |
544 | 498 |
my $self = shift; |
545 |
|
|
499 |
# die "was buggy for ar and not really in use at all"; |
|
546 | 500 |
my ($vc, $key, $type); |
547 | 501 |
if ( ref($self) eq 'SL::DB::Invoice' ) { |
548 | 502 |
$vc = 'customer'; |
549 |
$key = 'ap_id';
|
|
503 |
$key = 'ar_id'; # BUGGY ar_id
|
|
550 | 504 |
$type = 'ar'; |
551 | 505 |
} else { |
552 | 506 |
$vc = 'vendor'; |
... | ... | |
1046 | 1000 |
Unrounded total open amount of invoice (amount - paid). |
1047 | 1001 |
Doesn't take into account pending SEPA transfers. |
1048 | 1002 |
|
1049 |
=item C<open_percent> |
|
1050 |
|
|
1051 |
Percentage of the invoice that is still unpaid, e.g. 100,00 if no payments have |
|
1052 |
been made yet, 0,00 if fully paid. |
|
1053 |
|
|
1054 |
=item C<remaining_skonto_days> |
|
1055 |
|
|
1056 |
How many days skonto can still be taken, calculated from current day. Returns 0 |
|
1057 |
if current day is the max skonto date, and negative number if skonto date has |
|
1058 |
already passed. |
|
1059 |
|
|
1060 |
Returns undef if skonto is not configured for that invoice. |
|
1061 |
|
|
1062 | 1003 |
=item C<get_payment_suggestions %params> |
1063 | 1004 |
|
1064 | 1005 |
Creates data intended for an L.select_tag dropdown that can be used in a |
Auch abrufbar als: Unified diff
Payment-Helper: offensichtlich toten Code (Methoden) entfernt
Ferner einen Bug in einer Methode gefixt, die aber auch nie
richtig verwendet worden ist.