1 package SL::Presenter::Invoice;
 
   5 use SL::Presenter::EscapedText qw(escape is_escaped);
 
   7 use Exporter qw(import);
 
   8 our @EXPORT_OK = qw(invoice sales_invoice ar_transaction purchase_invoice ap_transaction);
 
  13   my ($invoice, %params) = @_;
 
  15   if ( $invoice->is_sales ) {
 
  16     if ( $invoice->invoice ) {
 
  17       return _is_ir_record($invoice, 'is', %params);
 
  19       return _is_ir_record($invoice, 'ar', %params);
 
  22     if ( $invoice->invoice ) {
 
  23       return _is_ir_record($invoice, 'ir', %params);
 
  25       return _is_ir_record($invoice, 'ap', %params);
 
  31   my ($invoice, %params) = @_;
 
  33   _is_ir_record($invoice, 'is', %params);
 
  37   my ($invoice, %params) = @_;
 
  39   _is_ir_record($invoice, 'ar', %params);
 
  42 sub purchase_invoice {
 
  43   my ($invoice, %params) = @_;
 
  45   _is_ir_record($invoice, 'ir', %params);
 
  49   my ($invoice, %params) = @_;
 
  51   _is_ir_record($invoice, 'ap', %params);
 
  55   my ($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=' . escape($invoice->id) . '">',
 
  63     escape($invoice->invnumber),
 
  64     $params{no_link} ? '' : '</a>',
 
  80 SL::Presenter::Invoice - Presenter module for sales invoice, AR
 
  81 transaction, purchase invoice and AP transaction Rose::DB objects
 
  86   my $object = SL::DB::Manager::Invoice->get_first(where => [ invoice => 1 ]);
 
  87   my $html   = SL::Presenter::Invoice::sales_invoice($object, display => 'inline');
 
  90   my $object = SL::DB::Manager::Invoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
 
  91   my $html   = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
 
  94   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ invoice => 1 ]);
 
  95   my $html   = SL::Presenter::Invoice::purchase_invoice($object, display => 'inline');
 
  98   my $object = SL::DB::Manager::PurchaseInvoice->get_first(where => [ or => [ invoice => undef, invoice => 0 ]]);
 
  99   my $html   = SL::Presenter::Invoice::ar_transaction($object, display => 'inline');
 
 101   # use with any of the above ar/ap/is/ir types:
 
 102   my $html   = SL::Presenter::Invoice::invoice($object, display => 'inline');
 
 108 =item C<invoice $object, %params>
 
 110 Returns a rendered version (actually an instance of
 
 111 L<SL::Presenter::EscapedText>) of an ar/ap/is/ir object C<$object> . Determines
 
 112 which type (sales or purchase, invoice or not) the object is.
 
 114 C<%params> can include:
 
 120 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 121 representations are identical and produce the invoice number linked
 
 122 to the corresponding 'edit' action.
 
 126 If falsish (the default) then the invoice number will be linked to the
 
 127 "edit invoice" dialog from the sales menu.
 
 131 =item C<sales_invoice $object, %params>
 
 133 Returns a rendered version (actually an instance of
 
 134 L<SL::Presenter::EscapedText>) of the sales invoice object C<$object>
 
 137 C<%params> can include:
 
 143 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 144 representations are identical and produce the invoice number linked
 
 145 to the corresponding 'edit' action.
 
 149 If falsish (the default) then the invoice number will be linked to the
 
 150 "edit invoice" dialog from the sales menu.
 
 154 =item C<ar_transaction $object, %params>
 
 156 Returns a rendered version (actually an instance of
 
 157 L<SL::Presenter::EscapedText>) of the AR transaction object C<$object>
 
 160 C<%params> can include:
 
 166 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 167 representations are identical and produce the invoice number linked
 
 168 to the corresponding 'edit' action.
 
 172 If falsish (the default) then the invoice number will be linked to the
 
 173 "edit invoice" dialog from the general ledger menu.
 
 177 =item C<purchase_invoice $object, %params>
 
 179 Returns a rendered version (actually an instance of
 
 180 L<SL::Presenter::EscapedText>) of the purchase invoice object
 
 183 C<%params> can include:
 
 189 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 190 representations are identical and produce the invoice number name
 
 191 linked to the corresponding 'edit' action.
 
 195 If falsish (the default) then the invoice number will be linked to
 
 196 the "edit invoice" dialog from the purchase menu.
 
 200 =item C<ap_transaction $object, %params>
 
 202 Returns a rendered version (actually an instance of
 
 203 L<SL::Presenter::EscapedText>) of the AP transaction object C<$object>
 
 206 C<%params> can include:
 
 212 Either C<inline> (the default) or C<table-cell>. At the moment both
 
 213 representations are identical and produce the invoice number linked
 
 214 to the corresponding 'edit' action.
 
 218 If falsish (the default) then the invoice number will be linked to the
 
 219 "edit invoice" dialog from the general ledger menu.
 
 231 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>