fixup editing w/manual inventory, RT#7010
[freeside.git] / httemplate / edit / elements / svc_Common.html
index ef04bd0..453d07f 100644 (file)
@@ -54,6 +54,7 @@
 
                  'field_callback' => sub {
                    my ($cgi, $object, $f) = @_;
+
                    my $columndef = $part_svc->part_svc_column($f->{'field'});
                    my $flag = $columndef->columnflag;
                    if ( $flag eq 'F' ) {
                                       ? 'fixed'
                                       : 'hidden';
                      $f->{'value'} = $columndef->columnvalue;
+                   } elsif ( $flag eq 'A' ) {
+                     $f->{'type'} = 'hidden';
+                   } elsif ( $flag eq 'M' ) {
+                     $f->{'empty_label'} = 'Select inventory item';
+                     $f->{'type'}        = 'select-table';
+                     $f->{'table'}       = 'inventory_item';
+                     $f->{'name_col'}    = 'item'; 
+                     $f->{'value_col'}   = 'item'; 
+                     $f->{'hashref'}     = {
+                                            'classnum'=>$columndef->columnvalue,
+                                            #'svcnum'  => '',
+                                           };
+                     $f->{'extra_sql'}   = 'AND ( svcnum IS NULL ';
+                     $f->{'extra_sql'}  .= ' OR svcnum = '. $object->svcnum
+                       if $object->svcnum;
+                     $f->{'extra_sql'}  .= ' ) ';
+                     $f->{'disable_empty'} = $object->svcnum ? 1 : 0,
+                   }
+
+                   if ( $f->{'type'} eq 'select-svc_pbx' ) {
+                     $f->{'include_opt_callback'} =
+                       sub { ( 'pkgnum'  => $pkgnum,
+                               'svcpart' => $svcpart,
+                             );
+                           };
                    }
+
                  },
 
                  'html_init' => sub {
 sub label_fixup {
   my( $part_svc, $opt ) = @_;
 
+  my $svcdb = $part_svc->svcdb;
+  require "FS/$svcdb.pm";
+
+  if ( UNIVERSAL::can("FS::$svcdb", 'table_info') ) {
+    $opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'};
+
+    my $fields = "FS::$svcdb"->table_info->{'fields'};
+    $opt->{'fields'} ||= [ grep { $_ ne 'svcnum' } keys %$fields ];
+
+    $opt->{labels} ||= {
+                         map { $_ => ( ref($fields->{$_})
+                                         ? $fields->{$_}{'label'}
+                                         : $fields->{$_}
+                                     );
+                             }
+                         keys %$fields
+                       };
+  }
+
   #false laziness w/view/svc_Common.html
   #override default labels with service-definition labels if applicable
   my $labels = $opt->{labels}; # with -> here
-  foreach my $field ( keys %$labels ) {
+  foreach my $field ( keys %{ $opt->{labels} } ) {
     my $col = $part_svc->part_svc_column($field);
     $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
   }