Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 59d0eec3

Von Sven Schöling vor etwa 8 Jahren hinzugefügt

  • ID 59d0eec32ad4697c075f8742c874a885728a3f9a
  • Vorgänger 29666b19
  • Nachfolger acfaa946

neue Presenter Infrastruktur

Testweise implementiert für Invoice/PurchaseInvoice/GLTransaction

Unterschiede anzeigen:

SL/DB/GLTransaction.pm
use SL::DB::MetaSetup::GLTransaction;
use SL::Locale::String qw(t8);
use List::Util qw(sum);
use SL::Presenter::GLTransaction;
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
__PACKAGE__->meta->make_manager_class;
......
__PACKAGE__->meta->initialize;
sub abbreviation {
my $self = shift;
my $abbreviation = $::locale->text('GL Transaction (abbreviation)');
$abbreviation .= "(" . $::locale->text('Storno (one letter abbreviation)') . ")" if $self->storno;
return $abbreviation;
}
sub displayable_type {
return t8('GL Transaction');
}
sub oneline_summary {
my ($self) = @_;
my $amount = sum map { $_->amount if $_->amount > 0 } @{$self->transactions};
$amount = $::form->format_amount(\%::myconfig, $amount, 2);
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->description, $self->reference, $amount, $self->transdate->to_kivitendo);
}
sub url_link {
return 'gl.pl?action=edit&id=' . $_[0]->id;
}
sub link {
my ($self) = @_;
return SL::Presenter->get->gl_transaction($self, display => 'inline');
}
sub invnumber {
return $_[0]->reference;
goto &reference;
}
sub abbreviation { $_[0]->presenter->abbreviation }
sub displayable_type { $_[0]->presenter->type }
sub link { $_[0]->presenter->link_tag }
sub oneline_summary { $_[0]->presenter->gist }
1;
SL/DB/Invoice.pm
use SL::DB::Helper::TransNumberGenerator;
use SL::Locale::String qw(t8);
use SL::DB::CustomVariable;
use SL::Presenter::Invoice;
__PACKAGE__->meta->add_relationship(
invoiceitems => {
......
return 'invoice';
}
sub displayable_state {
my $self = shift;
return $self->closed ? $::locale->text('closed') : $::locale->text('open');
}
sub displayable_type {
my ($self) = @_;
return t8('AR Transaction') if $self->invoice_type eq 'ar_transaction';
return t8('Credit Note') if $self->invoice_type eq 'credit_note';
return t8('Invoice') . "(" . t8('Storno') . ")" if $self->invoice_type eq 'invoice_storno';
return t8('Credit Note') . "(" . t8('Storno') . ")" if $self->invoice_type eq 'credit_note_storno';
return t8('Invoice');
}
sub displayable_name {
join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);
};
sub abbreviation {
my ($self) = @_;
return t8('AR Transaction (abbreviation)') if $self->invoice_type eq 'ar_transaction';
return t8('Credit note (one letter abbreviation)') if $self->invoice_type eq 'credit_note';
return t8('Invoice (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->invoice_type eq 'invoice_storno';
return t8('Credit note (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->invoice_type eq 'credit_note_storno';
return t8('Invoice (one letter abbreviation)');
}
sub oneline_summary {
my $self = shift;
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name,
$::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo);
}
sub date {
goto &transdate;
}
......
goto &customer;
}
sub url_link {
return ($_[0]->invoice ? "is" : "ar") . '.pl?action=edit&type=invoice&id=' . $_[0]->id;
}
sub link {
my ($self) = @_;
return SL::Presenter->get->invoice($self, display => 'inline');
}
sub abbreviation { $_[0]->presenter->abbreviation }
sub displayable_name { $_[0]->presenter->id }
sub displayable_state { $_[0]->presenter->state }
sub displayable_type { $_[0]->presenter->type }
sub link { $_[0]->presenter->link_tag; }
sub oneline_summary { $_[0]->presenter->gist }
sub url_link { $_[0]->presenter->url }
sub mark_as_paid {
my ($self) = @_;
SL/DB/PurchaseInvoice.pm
use SL::DB::Helper::Payment qw(:ALL);
use SL::Locale::String qw(t8);
use Rose::DB::Object::Helpers qw(has_loaded_related forget_related);
use SL::Presenter::PurchaseInvoice;
# The calculator hasn't been adjusted for purchase invoices yet.
# use SL::DB::Helper::PriceTaxCalculator;
......
goto &vendor;
}
sub abbreviation {
my $self = shift;
return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
return t8('Invoice (one letter abbreviation)');
};
sub oneline_summary {
my $self = shift;
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->vendor->name,
$::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo);
}
sub url_link {
return ($_[0]->invoice ? "ir" : "ap") . '.pl?action=edit&type=invoice&id=' . $_[0]->id;
}
sub link {
my ($self) = @_;
return SL::Presenter->get->invoice($self, display => 'inline');
}
sub invoice_type {
my ($self) = @_;
......
return 'purchase_invoice';
}
sub displayable_type {
my ($self) = @_;
return t8('AP Transaction') if $self->invoice_type eq 'ap_transaction';
return t8('Purchase Invoice');
}
sub displayable_name {
join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);
};
sub create_ap_row {
my ($self, %params) = @_;
# needs chart as param
......
return $acc_trans;
};
sub abbreviation { $_[0]->presenter->abbreviation }
sub displayable_type { $_[0]->presenter->type }
sub displayable_name { $_[0]->presenter->id }
sub link { $_[0]->presenter->link_tag }
sub oneline_summary { $_[0]->presenter->gist }
sub url_link { $_[0]->presenter->url }
sub mark_as_paid {
my ($self) = @_;
SL/Presenter.pm
use SL::Presenter::CustomerVendor;
use SL::Presenter::DeliveryOrder;
use SL::Presenter::EscapedText;
use SL::Presenter::Invoice;
use SL::Presenter::GL;
use SL::Presenter::Letter;
use SL::Presenter::Order;
use SL::Presenter::Part;
SL/Presenter/GL.pm
package SL::Presenter::GL;
use strict;
use parent qw(Exporter);
use Exporter qw(import);
our @EXPORT = qw(gl_transaction);
use Carp;
sub gl_transaction {
my ($self, $gl_transaction, %params) = @_;
$params{display} ||= 'inline';
croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
my $text = join '', (
$params{no_link} ? '' : '<a href="gl.pl?action=edit&amp;id=' . $self->escape($gl_transaction->id) . '">',
$self->escape($gl_transaction->reference),
$params{no_link} ? '' : '</a>',
);
return $self->escaped_text($text);
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
SL::Presenter::GL - Presenter module for GL transaction
=head1 SYNOPSIS
my $object = SL::DB::Manager::GLTransaction->get_first();
my $html = SL::Presenter->get->gl_transaction($object, display => 'inline');
=head1 FUNCTIONS
=over 4
=item C<gl_transaction $object, %params>
Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of a gl object C<$object>.
C<%params> can include:
=over 2
=item * display
Either C<inline> (the default) or C<table-cell>. At the moment both
representations are identical and produce the trans_id number linked
to the corresponding 'edit' action.
=item * no_link
If falsish (the default) then the trans_id number will be linked to the
"edit gl" dialog.
=back
=back
=head1 BUGS
Nothing here yet.
=head1 AUTHOR
G. Richardson E<lt>information@kivitendo-premium.deE<gt>
=cut
SL/Presenter/GLTransaction.pm
package SL::Presenter::GLTransaction;
use strict;
use parent qw(SL::Presenter::Object);
use SL::Locale::String qw(t8);
use List::Util qw(sum);
sub url {
my ($class, $object, %params) = @_;
return 'gl.pl?action=edit&id=' . $object->id;
}
sub id {
$_[1]->reference;
}
sub type {
t8('GL Transaction')
}
sub gist {
my ($class, $self, %params) = @_;
my $amount = sum map { $_->amount > 0 ? $_->amount : 0 } @{$self->transactions};
$amount = $::form->format_amount(\%::myconfig, $amount, 2);
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->description, $self->reference, $amount, $self->transdate->to_kivitendo);
}
sub abbreviation {
my ($class, $self, %params) = @_;
my $abbreviation = $::locale->text('GL Transaction (abbreviation)');
$abbreviation .= "(" . $::locale->text('Storno (one letter abbreviation)') . ")" if $self->storno;
$abbreviation;
}
1;
SL/Presenter/Invoice.pm
use strict;
use parent qw(Exporter);
use Exporter qw(import);
our @EXPORT = qw(invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
use parent qw(SL::Presenter::Object);
use SL::Locale::String qw(t8);
use Carp;
sub invoice {
my ($self, $invoice, %params) = @_;
if ( $invoice->is_sales ) {
if ( $invoice->invoice ) {
return _is_ir_record($self, $invoice, 'is', %params);
} else {
return _is_ir_record($self, $invoice, 'ar', %params);
}
} else {
if ( $invoice->invoice ) {
return _is_ir_record($self, $invoice, 'ir', %params);
} else {
return _is_ir_record($self, $invoice, 'ap', %params);
}
};
};
sub sales_invoice {
my ($self, $invoice, %params) = @_;
return _is_ir_record($self, $invoice, 'is', %params);
}
sub url {
my ($class, $object, %params) = @_;
sub ar_transaction {
my ($self, $invoice, %params) = @_;
return ($object->invoice ? "is" : "ar") . '.pl?action=edit&type=invoice&id=' . $object->id;
}
return _is_ir_record($self, $invoice, 'ar', %params);
sub id {
join ' ', grep $_, map $_[1]->$_, qw(displayable_type record_number);
}
sub purchase_invoice {
my ($self, $invoice, %params) = @_;
sub gist {
my ($class, $self, %params) = @_;
return _is_ir_record($self, $invoice, 'ir', %params);
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name,
$::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo);
}
sub ap_transaction {
my ($self, $invoice, %params) = @_;
sub state {
my ($class, $self, %params) = @_;
return _is_ir_record($self, $invoice, 'ap', %params);
$self->closed ? t8('closed') : t8('open');
}
sub _is_ir_record {
my ($self, $invoice, $controller, %params) = @_;
sub type {
my ($class, $self, %params) = @_;
$params{display} ||= 'inline';
return t8('AR Transaction') if $self->invoice_type eq 'ar_transaction';
return t8('Credit Note') if $self->invoice_type eq 'credit_note';
return t8('Invoice') . "(" . t8('Storno') . ")" if $self->invoice_type eq 'invoice_storno';
return t8('Credit Note') . "(" . t8('Storno') . ")" if $self->invoice_type eq 'credit_note_storno';
return t8('Invoice');
}
croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
sub abbreviation {
my ($class, $self, %params) = @_;
my $text = join '', (
$params{no_link} ? '' : '<a href="' . $self->escape($invoice->url_link) . '">',
$self->escape($invoice->invnumber),
$params{no_link} ? '' : '</a>',
);
return $self->escaped_text($text);
return t8('AR Transaction (abbreviation)') if $self->invoice_type eq 'ar_transaction';
return t8('Credit note (one letter abbreviation)') if $self->invoice_type eq 'credit_note';
return t8('Invoice (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->invoice_type eq 'invoice_storno';
return t8('Credit note (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->invoice_type eq 'credit_note_storno';
return t8('Invoice (one letter abbreviation)');
}
1;
SL/Presenter/Object.pm
package SL::Presenter::Object;
use strict;
use SL::Presenter;
use SL::Presenter::EscapedText;
sub link_tag {
my ($class, $object, %params) = @_;
SL::Presenter->escaped_text(
SL::Presenter::Tag::link(
SL::Presenter->get,
$class->url($object, %params),
$class->id($object, %params),
%params
),
);
}
sub url {
my ($class, $object, %params) = @_;
die 'must be overridden';
}
sub id {
my ($class, $object, %params) = @_;
die 'must be overridden';
}
sub gist {
my ($class, $object, %params) = @_;
die 'must be overridden';
}
sub table_cell {
goto &link_tag;
}
sub inline {
goto &link_tag;
}
sub render {
my ($class, $object, %params) = @_;
my $display = delete $params{display} || 'inline';
die "Unknown display type '$display'" unless $display && $class->can($display);
$class->$display($object, %params);
}
sub picker {
my ($class, $object, %params) = @_;
die 'must be overridden';
}
1;
__END__
=encoding utf-8
=head1 NAME
SL::Presenter::Object - base class for typed presenters
=head1 SYNOPSIS
# use as base class for presenter:
use parent qw(SL::Presenter::Object);
# implement some often used things
# all of these have signature ($class, $object, %params)
sub gist { $_[1]->number . ' ' . $_[1]->name }
sub url { 'controller.pl?action=This/edit&id=' . $_[1]->id }
=head1 CALLING CONVENTION
All methods in classes derived from this should have the signature C<$class,
$object, %params>. This way a proxy in C<SL::DB::Object> can be used to call
these methods on single objects.
=head1 METHODS
=over 4
=item C<url $class, $object, %params>
Returns an url to this object. Should handle callbacks.
Must be overridden.
=item C<id $class, $object, %params>
Returns an identification of the object intended for human readers. Should be
as concise and unique as possible.
Must be overridden
=item C<gist $class, $object, %params>
Returns a summary of the object. Should be one serialized line with as much
information as possible.
Must be overridden
=item C<link_tag $class, $object, %params>
Returns a link build from L<url> and L<id>.
=item C<table_cell $class, $object, %params>
Returns a presentation of this object intended for table cells.
Defaults to L<link_tag>.
=item C<inline $class, $object, %params>
Returns a presentation of this object intended for inlining in text.
Defaults to L<link_tag>.
=item C<render $class, $object, %params>
A dispatch method that extracts C<display> from params and calls the
appropriate method. If no C<display> is given, defaults to C<inline> for
historical reasons.
=item C<picker $class, $object, %params>
Renders a picker. If C<$object> is given it will be used as preselection.
Must be overridden.
=back
=head1 BUGS
I'm won't tell!
=head1 AUTHOR
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
=cut
SL/Presenter/PurchaseInvoice.pm
package SL::Presenter::PurchaseInvoice;
use strict;
use parent qw(SL::Presenter::Object);
use SL::Locale::String qw(t8);
use Carp;
sub url {
my ($class, $object, %params) = @_;
return ($object->invoice ? "ir" : "ap") . '.pl?action=edit&type=invoice&id=' . $object->id;
}
sub id {
join ' ', grep $_, map $_[1]->$_, qw(displayable_type record_number);
}
sub gist {
my ($class, $self, %params) = @_;
return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->vendor->name,
$::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo);
}
sub state {
my ($class, $self, %params) = @_;
$self->closed ? t8('closed') : t8('open');
}
sub type {
my ($class, $self, %params) = @_;
return t8('AP Transaction') if $self->invoice_type eq 'ap_transaction';
return t8('Purchase Invoice');
}
sub abbreviation {
my ($class, $self, %params) = @_;
return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
return t8('Invoice (one letter abbreviation)');
}
1;

Auch abrufbar als: Unified diff