Rechnungsmaske: "Drucken und Buchen" und Browser-Zurück entschärfen
[kivitendo-erp.git] / SL / DB / Letter.pm
index a7deeae..0753d67 100644 (file)
@@ -1,24 +1,16 @@
-# This file has been auto-generated only because it didn't exist.
-# Feel free to modify it at will; it will not be overwritten automatically.
-
 package SL::DB::Letter;
 
 use strict;
 
+use SL::DB::Helper::AttrHTML;
+use SL::DB::Helper::LinkedRecords;
 use SL::DB::MetaSetup::Letter;
 use SL::DB::Manager::Letter;
 
-__PACKAGE__->meta->add_relationships(
-  customer  => {
-    type                   => 'many to one',
-    class                  => 'SL::DB::Customer',
-    column_map             => { vc_id => 'id' },
-  },
-
-);
-
 __PACKAGE__->meta->initialize;
 
+__PACKAGE__->attr_html('body');
+
 sub new_from_draft {
   my ($class, $draft) = @_;
 
@@ -36,4 +28,28 @@ sub new_from_draft {
   $self;
 }
 
+sub is_sales {
+  die 'not an accessor' if @_ > 1;
+  $_[0]{customer_id} * 1;
+}
+
+sub has_customer_vendor {
+  my ($self) = @_;
+  die 'not an accessor' if @_ > 1;
+
+  return $self->is_sales
+    ? ($self->customer_id && $self->customer)
+    : ($self->vendor_id   && $self->vendor);
+}
+
+sub customer_vendor {
+  die 'not an accessor' if @_ > 1;
+  $_[0]->is_sales ? $_[0]->customer : $_[0]->vendor;
+}
+
+sub customer_vendor_id {
+  die 'not an accessor' if @_ > 1;
+  $_[0]->customer_id || $_[0]->vendor_id;
+}
+
 1;