-<%
-
- my %opt = @_;
-
- #my( $svcnum, $pkgnum, $svcpart, $part_svc );
- my( $pkgnum, $svcpart, $part_svc );
-
- #get & untaint pkgnum & svcpart
- my($query) = $cgi->keywords; #they're not proper cgi params
- if ( $query =~ /^pkgnum(\d+)-svcpart(\d+)$/ ) {
- $pkgnum = $1;
- $svcpart = $2;
- $cgi->delete_all(); #so the standard edit.html treats this correctly as new
- }
-
-%><%= include( 'edit.html',
+<% include( 'edit.html',
'menubar' => [],
'error_callback' => sub {
- my( $cgi, $svc_x ) = @_;
+ my( $cgi, $svc_x, $fields, $opt ) = @_;
#$svcnum = $svc_x->svcnum;
$pkgnum = $cgi->param('pkgnum');
$svcpart = $cgi->param('svcpart');
$part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
die "No part_svc entry!" unless $part_svc;
+
+ label_fixup($part_svc, $opt);
+
+ $svc_x->setfield('svcpart', $svcpart);
},
'edit_callback' => sub {
- my( $cgi, $svc_x ) = @_;
+ my( $cgi, $svc_x, $fields, $opt ) = @_;
#$svcnum = $svc_x->svcnum;
my $cust_svc = $svc_x->cust_svc
or die "Unknown (cust_svc) svcnum!";
$part_svc = qsearchs ('part_svc', { svcpart=>$svcpart });
die "No part_svc entry!" unless $part_svc;
+
+ label_fixup($part_svc, $opt);
},
- 'new_hash_callback' => sub {
+ 'new_hashref_callback' => sub {
#my( $cgi, $svc_x ) = @_;
{ svcpart => $svcpart };
},
'new_callback' => sub {
- my( $cgi, $svc_x ) = @_;;
+ my( $cgi, $svc_x, $fields, $opt ) = @_;;
$part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
die "No part_svc entry!" unless $part_svc;
+ label_fixup($part_svc, $opt);
+
#$svcnum='';
$svc_x->set_default_and_fixed;
},
'field_callback' => sub {
- my $f = shift;
+ my ($cgi, $object, $f) = @_;
+
my $columndef = $part_svc->part_svc_column($f->{'field'});
my $flag = $columndef->columnflag;
if ( $flag eq 'F' ) {
- $f->{'type'} = 'fixed';
+ $f->{'type'} = length($columndef->columnvalue)
+ ? 'fixed'
+ : 'hidden';
$f->{'value'} = $columndef->columnvalue;
+ } elsif ( $flag eq 'A' ) {
+ $f->{'type'} = 'hidden';
+ } elsif ( $flag eq 'M' ) {
+ $f->{'type'} = 'select-table';
+ $f->{'table'} = 'inventory_item';
+ $f->{'name_col'} = 'item';
+ $f->{'value_col'} = 'item';
+ $f->{'hashref'} = {
+ 'classnum' => $columndef->columnvalue,
+ 'svcnum' => '',
+ };
+ $f->{'empty_label'} = 'Select inventory item';
+ }
+
+ if ( $f->{'type'} eq 'select-svc_pbx' ) {
+ $f->{'include_opt_callback'} =
+ sub { ( 'pkgnum' => $pkgnum,
+ 'svcpart' => $svcpart,
+ );
+ };
+ }
+
+ },
+
+ 'html_init' => sub {
+ my $cust_main;
+ if ( $pkgnum ) {
+ my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum});
+ $cust_main = $cust_pkg->cust_main if $cust_pkg;
}
+ $cust_main
+ ? include( '/elements/small_custview.html',
+ $cust_main,
+ '',
+ 1,
+ popurl(2). "view/cust_main.cgi"
+ ). '<BR>'
+ : '';
+
},
'html_table_bottom' => sub {
qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!;
},
- 'debug' => 1,
-
%opt #pass through/override params
)
%>
+<%once>
+
+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 %{ $opt->{labels} } ) {
+ my $col = $part_svc->part_svc_column($field);
+ $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
+ }
+
+}
+
+</%once>
+<%init>
+
+my %opt = @_;
+
+#my( $svcnum, $pkgnum, $svcpart, $part_svc );
+my( $pkgnum, $svcpart, $part_svc );
+
+#get & untaint pkgnum & svcpart
+if ( ! $cgi->param('error')
+ && $cgi->param('pkgnum') && $cgi->param('svcpart')
+ )
+{
+ $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
+ $pkgnum = $1;
+ $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
+ $svcpart = $1;
+ #$cgi->delete_all(); #so edit.html treats this correctly as new??
+}
+
+</%init>