1 # This file has been auto-generated only because it didn't exist.
 
   2 # Feel free to modify it at will; it will not be overwritten automatically.
 
   4 package SL::DB::AccTransaction;
 
   8 use SL::DB::MetaSetup::AccTransaction;
 
   9 use SL::DB::Manager::AccTransaction;
 
  10 use SL::Locale::String qw(t8);
 
  12 require SL::DB::GLTransaction;
 
  13 require SL::DB::Invoice;
 
  14 require SL::DB::PurchaseInvoice;
 
  16 __PACKAGE__->meta->add_relationship(
 
  18     type         => 'many to one',
 
  19     class        => 'SL::DB::Invoice',
 
  20     column_map   => { trans_id => 'id' },
 
  23     type         => 'many to one',
 
  24     class        => 'SL::DB::PurchaseInvoice',
 
  25     column_map   => { trans_id => 'id' },
 
  28     type         => 'many to one',
 
  29     class        => 'SL::DB::GLTransaction',
 
  30     column_map   => { trans_id => 'id' },
 
  34 __PACKAGE__->meta->initialize;
 
  39   my @classes = qw(Invoice PurchaseInvoice GLTransaction);
 
  41   foreach my $class ( @classes ) {
 
  42     $class = 'SL::DB::' . $class;
 
  43     my $record = $class->new(id => $self->trans_id);
 
  44     return $record if $record->load(speculative => 1);
 
  52   my $ref = ref $self->record;
 
  54   return "ar" if $ref->isa('SL::DB::Invoice');
 
  55   return "ap" if $ref->isa('SL::DB::PurchaseInvoice');
 
  56   return "gl" if $ref->isa('SL::DB::GLTransaction');
 
  58   die "Can't find trans_id " . $self->trans_id . " in ar, ap or gl" unless $ref;
 
  62 sub transaction_name {
 
  65   my $ref = ref $self->record;
 
  66   my $name = "trans_id: " . $self->trans_id;
 
  67   if ( $self->get_type eq 'ar' ) {
 
  68     $name .= " (" . $self->record->abbreviation . " " . t8("AR") . ") " . t8("Invoice Number") . ": " . $self->record->invnumber;
 
  69   } elsif ( $self->get_type eq 'ap' ) {
 
  70     $name .= " (" . $self->record->abbreviation . " " . t8("AP") . ") " . t8("Invoice Number") . ": " . $self->record->invnumber;
 
  71   } elsif ( $self->get_type eq 'gl' ) {
 
  72     $name = "trans_id: " . $self->trans_id . " (" . $self->record->abbreviation . ") " . $self->record->reference . " - " . $self->record->description;
 
  74     die "can't determine type of acc_trans line with trans_id " . $self->trans_id;
 
  77   $name .= "   " . t8("Date") . ": " . $self->transdate->to_kivitendo;
 
  93 SL::DB::AccTransaction: Rose model for transactions (table "acc_trans")
 
 101 Returns the ar, ap or gl object of the current acc_trans object.
 
 104   my $acc_trans = SL::DB::Manager::AccTransaction->find_by( trans_id => '427' );
 
 105   my $record = $acc_trans->record;
 
 107 Each acc_trans entry is associated with an ar, ap or gl record. If we only have
 
 108 an acc_trans object, and we want to find out which kind of record it belongs
 
 109 to, we have to look for its trans_id in the tables ar, ap and gl. C<record>
 
 110 does this for you and returns an Invoice, PurchaseInvoice or GLTransaction
 
 113 We use the Rose::DB::Object load function with the C<speculative> parameter for
 
 114 each record type, which returns true if the load was successful, so we don't
 
 115 bother to check the ref of the object.
 
 119 Returns the type of transaction the acc_trans entry belongs to: ar, ap or gl.
 
 122  my $acc = SL::DB::Manager::AccTransaction->get_first();
 
 123  my $type = $acc->get_type;
 
 125 =item C<transaction_name>
 
 127 Generate a meaningful transaction name for an acc_trans line from the
 
 128 corresponding ar/ap/gl object, a combination of trans_id,
 
 129 invnumber/description, abbreviation. Can be used for better error output of the
 
 130 DATEV export and contains some database information, e.g. the trans_id, and is
 
 131 a kind of displayable_name for debugging or in the console.
 
 141 G. Richardson E<lt>information@kivitendo-premium.deE<gt>