rt# 74031 Implement forms for editing real estate inventory
authorMitch Jackson <mitch@freeside.biz>
Thu, 14 Dec 2017 00:14:43 +0000 (18:14 -0600)
committerMitch Jackson <mitch@freeside.biz>
Tue, 19 Dec 2017 23:10:53 +0000 (17:10 -0600)
httemplate/browse/realestate_location.html [new file with mode: 0644]
httemplate/browse/realestate_unit.html [new file with mode: 0644]
httemplate/edit/process/realestate_location.html [new file with mode: 0644]
httemplate/edit/process/realestate_unit.html [new file with mode: 0644]
httemplate/edit/realestate_location.html [new file with mode: 0644]
httemplate/edit/realestate_unit.html [new file with mode: 0644]
httemplate/elements/menu.html
httemplate/elements/select-realestate_location.html [new file with mode: 0644]
httemplate/elements/tr-select-realestate_location.html [new file with mode: 0644]

diff --git a/httemplate/browse/realestate_location.html b/httemplate/browse/realestate_location.html
new file mode 100644 (file)
index 0000000..be2cd11
--- /dev/null
@@ -0,0 +1,43 @@
+<% include( 'elements/browse.html',
+  title       => emt('Real Estate Locations'),
+  name        => 'real estate locations',
+
+  menubar => [
+    'Edit units'         => "${p}browse/realestate_unit.html",
+    'Add a new location' => "${p}edit/realestate_location.html",
+    'Add a new unit'     => "${p}edit/realestate_unit.html",
+  ],
+
+  query => { table => 'realestate_location' },
+  count_query => 'SELECT COUNT(*) FROM realestate_location',
+
+  header => [ 'Location', 'Address', 'Address 2', 'City', 'State', 'Zip' ],
+  fields => [
+    'location_title',
+    'address1',
+    'address2',
+    'city',
+    'state',
+    'zip'
+  ],
+  links => [
+    ["${p}edit/realestate_location.html?",  'realestatelocnum' ],
+  ],
+
+  agent_virt  => 1,
+  agent_pos   => 0,
+  disableable => 1,
+)
+%>
+<%init>
+
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die("access denied")
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+
+
+</%init>
diff --git a/httemplate/browse/realestate_unit.html b/httemplate/browse/realestate_unit.html
new file mode 100644 (file)
index 0000000..e71a598
--- /dev/null
@@ -0,0 +1,63 @@
+<% include( 'elements/browse.html',
+  title       => emt('Real Estate Inventory'),
+  name        => 'real estate inventory',
+
+  menubar => [
+    'Edit locations'     => "${p}browse/realestate_location.html",
+    'Add a new location' => "${p}edit/realestate_location.html",
+    'Add a new unit'     => "${p}edit/realestate_unit.html",
+  ],
+
+  query => {
+    table => 'realestate_unit',
+    select => join(', ',qw(
+      realestate_unit.*
+      realestate_location.location_title
+      cust_main.first
+      cust_main.last
+      cust_main.company
+    )),
+    addl_from => "
+      LEFT JOIN realestate_location
+        ON realestate_location.realestatelocnum
+           = realestate_unit.realestatelocnum
+      LEFT JOIN cust_main
+        ON realestate_unit.custnum = cust_main.custnum
+    ",
+  },
+
+  count_query => 'SELECT COUNT(*) FROM realestate_unit',
+
+  header => [ 'Location', 'Unit', 'Customer' ],
+  fields => [
+    'location_title',
+    'unit_title',
+    sub {
+      return '' unless $_[0]->custnum;
+      return $_[0]->company if $_[0]->company;
+      return $_[0]->first.' '.$_[0]->last;
+    },
+  ],
+  links => [
+    ["${p}edit/realestate_location?",  'realestatelocnum' ],
+    ["${p}edit/realestate_unit.html?", 'realestatenum' ],
+    ["${p}view/cust_main.cgi?",        'custnum' ]
+  ],
+
+  agent_virt  => 1,
+  agent_pos   => 0,
+  disableable => 1,
+)
+%>
+<%init>
+
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die("access denied")
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+
+
+</%init>
diff --git a/httemplate/edit/process/realestate_location.html b/httemplate/edit/process/realestate_location.html
new file mode 100644 (file)
index 0000000..ab5cf23
--- /dev/null
@@ -0,0 +1,14 @@
+<% include( 'elements/process.html',
+    table => 'realestate_location',
+    viewall_dir => 'browse',
+  )
+%>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied"
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+</%init>
diff --git a/httemplate/edit/process/realestate_unit.html b/httemplate/edit/process/realestate_unit.html
new file mode 100644 (file)
index 0000000..ba9b5dc
--- /dev/null
@@ -0,0 +1,13 @@
+<& elements/process.html,
+  'table'         => 'realestate_unit',
+  'viewall_dir'   => 'browse',
+&>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die("access denied")
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+</%init>
diff --git a/httemplate/edit/realestate_location.html b/httemplate/edit/realestate_location.html
new file mode 100644 (file)
index 0000000..254e57f
--- /dev/null
@@ -0,0 +1,71 @@
+<% include( 'elements/edit.html',
+ 'name_singular' => 'Real Estate Location',
+ 'table'  => 'realestate_location',
+
+ 'labels' => {
+    realestatelocnum => 'Location',
+    location_title => "Location",
+    address1       => "Address",
+    address2       => "Address",
+    city           => "City",
+    state          => "State",
+    zip            => "Zip-Code",
+    disabled       => "Disabled",
+  },
+  'fields' => [
+    { field => 'realestatelocnum', type => 'hidden' },
+
+    { field => 'location_title',
+      type=>'text',
+      size => 40,
+      maxlength => 80,
+    },
+    { field => 'address1',
+      type=>'text',
+      size => 40,
+      maxlength => 80,
+    },
+    { field => 'address2',
+      type=>'text',
+      size => 40,
+      maxlength => 80,
+    },
+    { field => 'city',
+      type=>'text',
+      size => 40,
+      maxlength => 80,
+    },
+    { field => 'state',
+      type=>'text',
+      size => 40,
+      maxlength => 80,
+    },
+    { field => 'zip',
+      type=>'text',
+      size => 5,
+      maxlength => 5,
+    },
+
+    { field => 'agentnum',
+      type => 'select-agent',
+    },
+    { field => 'disabled',
+      type=>'checkbox',
+      value=>'Y'
+    },
+  ],
+
+ 'viewall_dir' => 'browse',
+ 'agent_virt' => 1,
+)
+%>
+
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die("access denied")
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+</%init>
diff --git a/httemplate/edit/realestate_unit.html b/httemplate/edit/realestate_unit.html
new file mode 100644 (file)
index 0000000..b8bf1fa
--- /dev/null
@@ -0,0 +1,49 @@
+<% include( 'elements/edit.html',
+ 'name_singular' => 'Real Estate Unit',
+ 'table'  => 'realestate_unit',
+
+ 'labels' => {
+    realestatenum  => 'Ref No',
+    unit_title => 'Unit Title',
+    agentnum => 'Agent',
+    realestatelocnum => 'Location',
+  },
+  'fields' => [
+    { field => 'realestatenum', type => 'hidden' },
+    { field => 'custnum', type => 'hidden' },
+
+    { field => 'unit_title',
+      type=>'text',
+      size => 40,
+    },
+    { field => 'realestatelocnum',
+      type => 'select-realestate_location',
+
+      # possible todo:
+      # I'd like to have this field disabled for editing on existing records,
+      # and only show the full selectbox for new records.
+
+    },
+    { field => 'agentnum',
+      type => 'select-agent',
+    },
+    { field => 'disabled',
+      type=>'checkbox',
+      value=>'Y'
+    },
+  ],
+
+ 'viewall_dir' => 'browse',
+ 'agent_virt' => 1,
+)
+%>
+
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+die("access denied")
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
+
+</%init>
index 3532e60..0a73d71 100644 (file)
@@ -829,12 +829,12 @@ $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/realestate_inventory.html', 'Setup inventory classes and stock inventory' ]
+$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.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' ]
+$config_misc{'Real estate inventory'} = [ $fsurl.'browse/realestate_unit.html', 'Setup real estate inventory' ]
   if $curuser->access_right('Edit realestate inventory')
   || $curuser->access_right('Edit global inventory')
   || $curuser->access_right('Configuration');
diff --git a/httemplate/elements/select-realestate_location.html b/httemplate/elements/select-realestate_location.html
new file mode 100644 (file)
index 0000000..001ed3e
--- /dev/null
@@ -0,0 +1,32 @@
+<%doc>
+
+  Displays a selectbox populated with values from realestate_location.
+  key:   realestate_location.realestatenum
+  value: realestate_location.location_title
+
+</%doc>
+
+<% include( '/elements/select-table.html',
+    %opt,
+    table         => 'realestate_location',
+    name_col      => 'location_title',
+    hashref       => { 'disabled' => '' },
+    value         => $select_value,
+    disable_empty => 1,
+  )
+%>
+
+<%init>
+
+#
+# possible todo:
+# I'd like to change the behavior of this select based on if
+# a new item is being created, or an existing item being edited
+
+my %opt = @_;
+my $select_value = $opt{'curr_value'} || $opt{'value'};
+
+# use Data::Dumper qw(Dumper);
+# print Dumper(\%opt);
+
+</%init>
diff --git a/httemplate/elements/tr-select-realestate_location.html b/httemplate/elements/tr-select-realestate_location.html
new file mode 100644 (file)
index 0000000..1367886
--- /dev/null
@@ -0,0 +1,17 @@
+<TR>
+  <TH ALIGN="right"><% $opt{'label'} || 'Real Estate Location' %></TD>
+  <TD>
+    <% include( '/elements/select-realestate_location.html',
+        'curr_value' => $curr_value,
+        %opt
+      )
+    %>
+  </TD>
+</TR>
+
+<%init>
+
+my %opt = @_;
+my $curr_value = $opt{'curr_value'} || $opt{'value'};
+
+</%init>