1 package SL::DB::PurchaseInvoice;
 
   7 use SL::DB::MetaSetup::PurchaseInvoice;
 
   8 use SL::DB::Manager::PurchaseInvoice;
 
   9 use SL::DB::Helper::AttrHTML;
 
  10 use SL::DB::Helper::AttrSorted;
 
  11 use SL::DB::Helper::LinkedRecords;
 
  12 use SL::DB::Helper::Payment qw(:ALL);
 
  13 use SL::Locale::String qw(t8);
 
  14 use Rose::DB::Object::Helpers qw(has_loaded_related forget_related);
 
  16 # The calculator hasn't been adjusted for purchase invoices yet.
 
  17 # use SL::DB::Helper::PriceTaxCalculator;
 
  19 __PACKAGE__->meta->add_relationship(
 
  21     type         => 'one to many',
 
  22     class        => 'SL::DB::InvoiceItem',
 
  23     column_map   => { id => 'trans_id' },
 
  24     manager_args => { with_objects => [ 'part' ] }
 
  26   sepa_export_items => {
 
  27     type            => 'one to many',
 
  28     class           => 'SL::DB::SepaExportItem',
 
  29     column_map      => { id => 'ap_id' },
 
  30     manager_args    => { with_objects => [ 'sepa_export' ] }
 
  33     type            => 'many to many',
 
  34     map_class       => 'SL::DB::SepaExportItem',
 
  36     map_to          => 'sepa_export',
 
  40     class           => 'SL::DB::Shipto',
 
  41     column_map      => { id => 'trans_id' },
 
  42     query_args      => [ module => 'AP' ],
 
  45     type         => 'one to many',
 
  46     class        => 'SL::DB::AccTransaction',
 
  47     column_map   => { id => 'trans_id' },
 
  48     manager_args => { with_objects => [ 'chart' ],
 
  49                       sort_by      => 'acc_trans_id ASC' }
 
  53 __PACKAGE__->meta->initialize;
 
  55 __PACKAGE__->attr_html('notes');
 
  56 __PACKAGE__->attr_sorted('items');
 
  58 sub items { goto &invoiceitems; }
 
  59 sub add_items { goto &add_invoiceitems; }
 
  60 sub record_number { goto &invnumber; };
 
  63   # For compatibility with Order, DeliveryOrder
 
  64   croak 'not an accessor' if @_ > 1;
 
  83   return t8('AP Transaction (abbreviation)') if !$self->invoice && !$self->storno;
 
  84   return t8('AP Transaction (abbreviation)') . '(' . t8('Storno (one letter abbreviation)') . ')' if !$self->invoice && $self->storno;
 
  85   return t8('Invoice (one letter abbreviation)'). '(' . t8('Storno (one letter abbreviation)') . ')' if $self->storno;
 
  86   return t8('Invoice (one letter abbreviation)');
 
  94   $html   = SL::Presenter->get->purchase_invoice($self, display => 'inline') if $self->invoice;
 
  95   $html   = SL::Presenter->get->ap_transaction($self, display => 'inline') if !$self->invoice;
 
 103   return 'ap_transaction' if !$self->invoice;
 
 104   return 'purchase_invoice';
 
 107 sub displayable_type {
 
 110   return t8('AP Transaction')    if $self->invoice_type eq 'ap_transaction';
 
 111   return t8('Purchase Invoice');
 
 114 sub displayable_name {
 
 115   join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);