rt# 74031 work in progress
[freeside.git] / FS / FS / realestate_property.pm
diff --git a/FS/FS/realestate_property.pm b/FS/FS/realestate_property.pm
new file mode 100644 (file)
index 0000000..4e56417
--- /dev/null
@@ -0,0 +1,176 @@
+package FS::realestate_property;
+use strict;
+use warnings;
+use Carp qw(croak);
+
+use base 'FS::Record';
+use FS::Record qw(qsearch qsearchs);
+
+=head1 NAME
+
+FS::realestate_property - Object representing a realestate_property record
+
+=head1 SYNOPSIS
+
+  use FS::realestate_property;
+
+  $record = new FS:realestate_property  \%values;
+  $record = new FS::realestate_property {
+    title    => 'Superdome',
+    address1 => '1500 Sugar Bowl Dr',
+    city     => 'New Orleans',
+    state    => 'LA',
+    zip      => '70112',
+    disabled => 0,
+    agentnum => 1,
+  };
+
+  $error = $record->insert;
+  $error = $new_rec->replace($record)
+  $error = $record->check;
+
+  $sub_record = $record->add_subproperty('Box Seat No. 42');
+
+  @subprops = $record->subproperties;
+  @subprops = $record->enabled_subproperties;
+
+=head1 DESCRIPTION
+
+An FS::realestate_property object represents a real estate property.  This
+object may represent a single property, such as a rental house.  It may also
+represent a group of properties sharing a common address or identifier, such
+as a shopping mall, apartment complex, or office building.
+
+FS::realestate_property inherits from FS::Record.
+
+The following fields are currently supported:
+
+=over 4
+
+=item propnum
+
+=item agentnum
+
+=item title
+
+=item address1 *optional
+
+=item address2 *optional
+
+=item city     *optional
+
+=item state    *optional
+
+=item zip      *optional
+
+=item disabled
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF (see L<FS::Record>)
+
+=cut
+
+sub table {'realestate_property';}
+
+=item insert (see L<FS::Record>)
+
+=item delete
+
+  FS::realestate_property 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_property 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 this object
+
+=cut
+
+sub agent {
+  my $self = shift;
+  return undef unless $self->agentnum;
+  return qsearchs('agent', {agentnum => $self->agentnum} );
+}
+
+
+=item subproperties
+
+Returns all subproperties linked to this property
+
+=cut
+
+sub subproperties {
+  qsearch('realestate_subproperty', {propnum => shift->propnum} );
+}
+
+
+=item enabled_subproperties
+
+Returns all subproperties linked to this property where disabled = 0
+
+=cut
+
+sub enabled_subproperties {
+  qsearch( 'realestate_subproperty', {
+    propnum => shift->propnum,
+    disabled => 0,
+  });
+}
+
+=item add_subproperty SUBPROPERTY_TITLE
+
+Create a new subproperty record for this property
+
+=cut
+
+sub add_subproperty {
+  my ($self, $subtitle) = @_;
+  croak "add_subproperty() requires a \$subtitle parameter" unless $subtitle;
+
+  my $subp = new FS::realestate_subproperty {
+    propnum  => $self->propnum,
+    subtitle => $subtitle,
+    disabled => 0,
+  };
+  my $err = $subp->insert;
+  die "Error inserting subproperty: $err" if $err;
+  $subp;
+}
+
+
+=back
+
+=head1 SUBROUTINES
+
+=over 4
+
+=cut
+
+
+=back
+
+=head1 SEE ALSO
+
+L<FS::record>, L<FS::realestate_subproperty>, L<FS::svc_realestate>
+
+=cut
+
+1;