RDBO: Manager-Klasse für Vendor
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 12 May 2014 07:17:31 +0000 (09:17 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 14 May 2014 07:39:30 +0000 (09:39 +0200)
SL/DB/Manager/Vendor.pm [new file with mode: 0644]
SL/DB/Vendor.pm

diff --git a/SL/DB/Manager/Vendor.pm b/SL/DB/Manager/Vendor.pm
new file mode 100644 (file)
index 0000000..838d12b
--- /dev/null
@@ -0,0 +1,31 @@
+package SL::DB::Manager::Vendor;
+
+use strict;
+
+use SL::DB::Helper::Manager;
+use base qw(SL::DB::Helper::Manager);
+
+use SL::DB::Helper::Filtered;
+use SL::DB::Helper::Sorted;
+
+sub object_class { 'SL::DB::Vendor' }
+
+__PACKAGE__->make_manager_methods;
+
+__PACKAGE__->add_filter_specs(
+  all => sub {
+    my ($key, $value, $prefix) = @_;
+    return or => [ map { $prefix . $_ => $value } qw(vendornumber name) ]
+  }
+);
+
+sub _sort_spec {
+  return (
+    default => [ 'name', 1 ],
+    columns => {
+      SIMPLE => 'ALL',
+      map { ( $_ => "lower(vendor.$_)" ) } qw(account_number bank bank_code bcc bic cc city contact country department_1 department_2 depositor email fax greeting homepage iban language
+                                              name notes phone street taxnumber user_password username ustid v_customer_id vendornumber zipcode)
+    });
+}
+1;
index 23886ea..8a1ea46 100644 (file)
@@ -3,6 +3,7 @@ package SL::DB::Vendor;
 use strict;
 
 use SL::DB::MetaSetup::Vendor;
+use SL::DB::Manager::Vendor;
 use SL::DB::Helper::TransNumberGenerator;
 use SL::DB::Helper::CustomVariables (
   module      => 'CT',
@@ -27,7 +28,6 @@ __PACKAGE__->meta->add_relationship(
   },
 );
 
-__PACKAGE__->meta->make_manager_class;
 __PACKAGE__->meta->initialize;
 
 __PACKAGE__->before_save('_before_save_set_vendornumber');
@@ -39,6 +39,12 @@ sub _before_save_set_vendornumber {
   return 1;
 }
 
+sub displayable_name {
+  my $self = shift;
+
+  return join ' ', grep $_, $self->vendornumber, $self->name;
+}
+
 sub is_customer { 0 };
 sub is_vendor   { 1 };