1 package SL::Presenter::Invoice;
 
   5 use parent qw(Exporter);
 
   7 use Exporter qw(import);
 
   8 our @EXPORT = qw(invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
 
  13   my ($self, $invoice, %params) = @_;
 
  15   if ( $invoice->is_sales ) {
 
  16     if ( $invoice->invoice ) {
 
  17       return _is_ir_record($self, $invoice, 'is', %params);
 
  19       return _is_ir_record($self, $invoice, 'ar', %params);
 
  22     if ( $invoice->invoice ) {
 
  23       return _is_ir_record($self, $invoice, 'ir', %params);
 
  25       return _is_ir_record($self, $invoice, 'ap', %params);
 
  31   my ($self, $invoice, %params) = @_;
 
  33   return _is_ir_record($self, $invoice, 'is', %params);
 
  37   my ($self, $invoice, %params) = @_;
 
  39   return _is_ir_record($self, $invoice, 'ar', %params);
 
  42 sub purchase_invoice {
 
  43   my ($self, $invoice, %params) = @_;
 
  45   return _is_ir_record($self, $invoice, 'ir', %params);
 
  49   my ($self, $invoice, %params) = @_;
 
  51   return _is_ir_record($self, $invoice, 'ap', %params);
 
  55   my ($self, $invoice, $controller, %params) = @_;
 
  57   $params{display} ||= 'inline';
 
  59   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
 
  62     $params{no_link} ? '' : '<a href="' . $controller . '.pl?action=edit&type=invoice&id=' . $self->escape($invoice->id) . '">',
 
  63     $self->escape($invoice->invnumber),
 
  64     $params{no_link} ? '' : '</a>',
 
  66   return $self->escaped_text($text);
 
  79 SL::Presenter::Invoice - Presenter module for sales invoice, AR
 
  80 transaction, purchase invoice and AP transaction Rose::DB objects
 
  85   my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
 
  86   my $html   = SL::Presenter->get->sales_invoice($object, display => 'inline');
 
  89   my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
 
  90   my $html   = SL::Presenter->get->ar_transaction($object, display => 'inline');
 
  93   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
 
  94   my $html   = SL::Presenter->get->purchase_invoice($object, display => 'inline');
 
  97   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
 
  98   my $html   = SL::Presenter->get->ar_transaction($object, display => 'inline');
 
 100   # use with any of the above ar/ap/is/ir types:
 
 101   my $html   = SL::Presenter->get->invoice($object, display => 'inline');
 
 107 =item C<invoice $object, %params>
 
 109 Returns a rendered version (actually an instance of
 
 110 L<SL::Presenter::EscapedText>) of an ar/ap/is/ir object C<$object> . Determines
 
 111 which type (sales or purchase, invoice or not) the object is.
 
 113 C<%params> can include:
 
 119 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 120 representations are identical and produce the invoice number linked
 
 121 to the corresponding 'edit' action.
 
 125 If falsish (the default) then the invoice number will be linked to the
 
 126 "edit invoice" dialog from the sales menu.
 
 130 =item C<sales_invoice $object, %params>
 
 132 Returns a rendered version (actually an instance of
 
 133 L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
 
 136 C<%params> can include:
 
 142 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 143 representations are identical and produce the invoice number linked
 
 144 to the corresponding 'edit' action.
 
 148 If falsish (the default) then the invoice number will be linked to the
 
 149 "edit invoice" dialog from the sales menu.
 
 153 =item C<ar_transaction $object, %params>
 
 155 Returns a rendered version (actually an instance of
 
 156 L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
 
 159 C<%params> can include:
 
 165 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 166 representations are identical and produce the invoice number linked
 
 167 to the corresponding 'edit' action.
 
 171 If falsish (the default) then the invoice number will be linked to the
 
 172 "edit invoice" dialog from the general ledger menu.
 
 176 =item C<purchase_invoice $object, %params>
 
 178 Returns a rendered version (actually an instance of
 
 179 L<SL::Presenter::EscapedText>) of the purchase invoice object
 
 182 C<%params> can include:
 
 188 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 189 representations are identical and produce the invoice number name
 
 190 linked to the corresponding 'edit' action.
 
 194 If falsish (the default) then the invoice number will be linked to
 
 195 the "edit invoice" dialog from the purchase menu.
 
 199 =item C<ap_transaction $object, %params>
 
 201 Returns a rendered version (actually an instance of
 
 202 L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
 
 205 C<%params> can include:
 
 211 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 212 representations are identical and produce the invoice number linked
 
 213 to the corresponding 'edit' action.
 
 217 If falsish (the default) then the invoice number will be linked to the
 
 218 "edit invoice" dialog from the general ledger menu.
 
 230 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>