summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2017-12-10 03:40:06 +0000
committerMitch Jackson <mitch@freeside.biz>2017-12-19 17:10:53 -0600
commit4c1510910211827eec5cb6a4bd3726857e6fb94c (patch)
tree6bbd9337ec93278dac8b95aa7d0cdc7f0bd59d36
parent0521301227e488e4bef7a65dd814b1489cd06972 (diff)
rt# 74031 work in progress
- Update schemas - First draft for FS::realestate_property - and FS::realestate_subproperty - worthless test for new modules - Add a menuitem for property management
-rw-r--r--FS/FS/Schema.pm12
-rw-r--r--FS/FS/realestate_property.pm176
-rw-r--r--FS/FS/realestate_subproperty.pm125
-rw-r--r--FS/t/realestate_property.t5
-rw-r--r--FS/t/realestate_subproperty.t5
-rw-r--r--httemplate/elements/menu.html8
6 files changed, 323 insertions, 8 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 6d88204..b94407b 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -7658,14 +7658,14 @@ sub tables_hashref {
'realestate_subproperty' => {
'columns' => [
- 'spropnum', 'serial', '', '', '', '',
- 'propnum', 'int', '', '', '', '',
- 'subtitle', 'varchar', '', $char_d, '', '',
- 'disabled', 'char', '', 1, '0', '',
+ 'subpropnum', 'serial', '', '', '', '',
+ 'propnum', 'int', '', '', '', '',
+ 'subtitle', 'varchar', '', $char_d, '', '',
+ 'disabled', 'char', '', 1, '0', '',
],
- 'primary_key' => 'spropnum',
+ 'primary_key' => 'subpropnum',
'unique' => [],
- 'index' => [ ['propnum'] ],
+ 'index' => [ ['propnum'],['subtitle'] ],
'foreign_keys' => [
{columns => ['propnum'], table => 'realestate_property'}
],
diff --git a/FS/FS/realestate_property.pm b/FS/FS/realestate_property.pm
new file mode 100644
index 0000000..4e56417
--- /dev/null
+++ b/FS/FS/realestate_property.pm
@@ -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;
diff --git a/FS/FS/realestate_subproperty.pm b/FS/FS/realestate_subproperty.pm
new file mode 100644
index 0000000..5a93934
--- /dev/null
+++ b/FS/FS/realestate_subproperty.pm
@@ -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;
diff --git a/FS/t/realestate_property.t b/FS/t/realestate_property.t
new file mode 100644
index 0000000..af7f2f4
--- /dev/null
+++ b/FS/t/realestate_property.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::realestate_property;
+$loaded=1;
+print "ok 1\n";
diff --git a/FS/t/realestate_subproperty.t b/FS/t/realestate_subproperty.t
new file mode 100644
index 0000000..0f00eee
--- /dev/null
+++ b/FS/t/realestate_subproperty.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::realestate_subproperty;
+$loaded=1;
+print "ok 1\n";
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index defcc49..3532e60 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -829,11 +829,16 @@ $config_misc{'Custom fields'} = [ $fsurl.'browse/part_virtual_field.html', 'Loca
if $curuser->access_right('Edit custom fields');
$config_misc{'Translation strings'} = [ $fsurl.'browse/msgcat.html', 'Translations and other customizable labels for each locale' ]
if $curuser->access_right('Configuration');
-$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ]
+$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/realestate_inventory.html', 'Setup inventory classes and stock inventory' ]
if $curuser->access_right('Edit inventory')
|| $curuser->access_right('Edit global inventory')
|| $curuser->access_right('Configuration');
+$config_misc{'Real estate inventory'} = [ $fsurl.'browse/inventory_realestate.html', 'Setup real estate inventory' ]
+ if $curuser->access_right('Edit realestate inventory')
+ || $curuser->access_right('Edit global inventory')
+ || $curuser->access_right('Configuration');
+
$config_misc{'Upload targets'} = [ $fsurl.'browse/upload_target.html', 'Billing and payment upload destinations' ]
if $curuser->access_right('Configuration');
@@ -1038,4 +1043,3 @@ sub submenu {
}
</%init>
-