rt# 74031 work in progress
[freeside.git] / FS / FS / realestate_subproperty.pm
diff --git a/FS/FS/realestate_subproperty.pm b/FS/FS/realestate_subproperty.pm
new file mode 100644 (file)
index 0000000..5a93934
--- /dev/null
@@ -0,0 +1,125 @@
+package FS::realestate_subproperty;
+use strict;
+use warnings;
+use Carp qw(croak);
+
+use base 'FS::Record';
+
+use FS::Record qw(qsearchs);
+
+=head1 NAME
+
+FS::realestate_subproperty - Object representing a realestate_subproperty record
+
+=head1 SYNOPSIS
+
+  use FS::realestate_subproperty;
+
+  $record = new FS::realestate_subproperty \%values;
+  $record = new FS::realestate_subproperty {
+    propnum => 65535,
+    subtitle => 'Box Seat No. 42',
+  };
+
+  $error = $record->insert;
+  $error = new_rec->replace($record);
+  $error = $record->check;
+
+  $parent = $record->property;
+
+=head1 DESCRIPTION
+
+An FS::realestate_subproperty object represents a unit of real estate property.
+Every L<FS::realestate_property> must contain at least one subproperty, or unit,
+which is the actual unit considered for sale, rent, etc as tied to
+L<FS::svc_realestate>.
+
+FS::realestate_subproperty inherits from FS::Record.
+
+The following fields are currently supported:
+
+=over 4
+
+=item subpropnum
+
+=item propnum
+
+=item subtitle
+
+=item disabled
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF (see L<FS::Record>)
+
+=cut
+
+sub table {'realestate_subproperty';}
+
+=item insert (see L<FS::Record>)
+
+=item delete
+
+  FS::realestate_subproperty records should never be deleted, only disabled
+
+=cut
+
+sub delete {
+  # Once this record has been associated with a customer in any way, it
+  # should not be deleted.  todo perhaps, add a is_deletable function that
+  # checks if the record has ever actually been used, and allows deletion
+  # if it hasn't.  (entered in error, etc).
+  croak "FS::realestate_subproperty records should never be deleted";
+}
+
+=item replace OLD_RECORD (see L<FS::Record>)
+
+=item check (see L<FS::Record>)
+
+=item agent
+
+Returns the associated agent, if any, for the parent L<FS::realestate_property>
+
+=cut
+
+sub agent {
+  shift->property->agent;
+}
+
+=item property
+
+Returns the associated parent L<FS::realestate_property> record
+
+=cut
+
+sub property {
+  my $self = shift;
+  exists $self->{property}
+  ? $self->{property}
+  : $self->{property} = qsearchs('realestate_property',$self->propnum);
+}
+
+=back
+
+=head1 SUBROUTINES
+
+=over 4
+
+=cut
+
+
+
+
+=back
+
+=head1 SEE ALSO
+
+L<FS::record>, L<FS::realestate_property>, L<FS::svc_realestate>
+
+=cut
+
+1;