agent-virtualize credit card surcharge percentage, RT#72961
[freeside.git] / FS / FS / part_device.pm
index 79a534a..ac98740 100644 (file)
@@ -1,8 +1,10 @@
 package FS::part_device;
 
 use strict;
-use base qw( FS::Record );
-use FS::Record; # qw( qsearch qsearchs );
+use base qw( FS::Record FS::m2m_Common );
+use FS::Record qw( qsearch qsearchs );
+use FS::part_export;
+use FS::export_device;
 
 =head1 NAME
 
@@ -36,8 +38,15 @@ primary key
 
 =item devicename
 
-devicename
+device name (used in Freeside)
 
+=item inventory_classnum
+
+L<FS::inventory_class> used to track inventory of these devices.
+
+=item title
+
+external device name (for export)
 
 =back
 
@@ -101,12 +110,39 @@ sub check {
   my $error = 
     $self->ut_numbern('devicepart')
     || $self->ut_text('devicename')
+    || $self->ut_foreign_keyn('inventory_classnum', 'inventory_class', 'classnum')
+    || $self->ut_textn('title')
   ;
   return $error if $error;
 
   $self->SUPER::check;
 }
 
+=item part_export
+
+Returns a list of all exports (see L<FS::part_export>) for this device.
+
+=cut
+
+sub part_export {
+  my $self = shift;
+  map { qsearchs( 'part_export', { 'exportnum' => $_->exportnum } ) }
+    qsearch( 'export_device', { 'devicepart' => $self->devicepart } );
+}
+
+=item inventory_class
+
+Returns the inventory class (see L<FS::inventory_class>) for this device, 
+if any.
+
+=cut
+
+sub inventory_class {
+  my $self = shift;
+  return '' unless $self->inventory_classnum;
+  qsearchs('inventory_class', { 'classnum' => $self->inventory_classnum });
+}
+
 sub process_batch_import {
   my $job = shift;