agent type on package add/edit (ticket 1446)
authorjeff <jeff>
Thu, 8 Feb 2007 01:46:45 +0000 (01:46 +0000)
committerjeff <jeff>
Thu, 8 Feb 2007 01:46:45 +0000 (01:46 +0000)
FS/FS/part_pkg.pm
htetc/handler.pl
httemplate/edit/part_pkg.cgi
httemplate/edit/process/part_pkg.cgi
httemplate/elements/select-table.html

index 73413f8..e4c13aa 100644 (file)
@@ -14,7 +14,7 @@ use FS::type_pkgs;
 use FS::part_pkg_option;
 use FS::pkg_class;
 
-@ISA = qw( FS::Record ); # FS::option_Common ); # this can use option_Common
+@ISA = qw( FS::m2m_Common FS::Record ); # FS::option_Common ); # this can use option_Common
                                                 # when all the plandata bs is
                                                 # gone
 
index f742e91..164da37 100644 (file)
@@ -119,7 +119,7 @@ sub handler
       use Chart::LinesPoints;
       use Chart::Mountain;
       use Color::Scheme;
-      use HTML::Widgets::SelectLayers 0.06;
+      use HTML::Widgets::SelectLayers 0.07;
       use Locale::Country;
       use FS;
       use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
index f970508..a84fafa 100755 (executable)
 %my ($query) = $cgi->keywords;
 %
 %my $part_pkg = '';
+%my @agent_type = ();
 %if ( $cgi->param('error') ) {
 %  $part_pkg = new FS::part_pkg ( {
 %    map { $_, scalar($cgi->param($_)) } fields('part_pkg')
 %  } );
+%  (@agent_type) = $cgi->param('agent_type');
 %}
 %
 %my $action = '';
@@ -30,6 +32,8 @@
 %  $part_pkg ||= $clone_part_pkg->clone;
 %  $part_pkg->disabled('Y'); #isn't sticky on errors
 %} elsif ( $query && $query =~ /^(\d+)$/ ) {
+%  (@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1})
+%    unless $part_pkg;
 %  $part_pkg ||= qsearchs('part_pkg',{'pkgpart'=>$1});
 %  $pkgpart = $part_pkg->pkgpart;
 %} else {
@@ -153,6 +157,25 @@ Line-item revenue recognition
 % }
 </TABLE>
 
+</TD><TD VALIGN="top">
+
+Reseller information
+<% ntable("#cccccc", 2) %>
+  <TR>
+    <TD ALIGN="right"><% 'Agent Types' %></TD>
+    <TD>
+      <% include( '/elements/select-table.html',
+                  'element_name' => 'agent_type',
+                  'table'        => 'agent_type',
+                 'name_col'     => 'atype',
+                 'value'        => \@agent_type,
+                 'empty_label'  => '(none)',
+                 'element_etc'  => 'multiple size="10"',
+                )
+      %>
+    </TD>
+  </TR>
+</TABLE>
 </TD></TR></TABLE>
 %
 %
@@ -248,7 +271,7 @@ Line-item revenue recognition
 %#} else {
 %#  push @fixups, 'taxclass'; #hidden
 %#}
-%my @form_elements = ( 'classnum', 'taxclass' );
+%my @form_elements = ( 'classnum', 'taxclass', 'agent_type' );
 %
 %my @form_radio = ();
 %if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
@@ -267,7 +290,7 @@ Line-item revenue recognition
 %  'form_action'    => 'process/part_pkg.cgi',
 %  'form_elements'  => \@form_elements,
 %  'form_text'      => [ qw(pkg comment promo_code clone pkgnum pkgpart),
-%                        qw(pay_weight credit_weight), #keys(%weight),
+%                        qw(pay_weight credit_weight),
 %                        @fixups,
 %                      ],
 %  'form_checkbox'  => [ qw(setuptax recurtax disabled) ],
@@ -305,7 +328,7 @@ Line-item revenue recognition
 %                 ( exists($plandata{$field})
 %                     ? $plandata{$field}
 %                     : $href->{$field}{'default'} ).
-%                 qq!" onChange="fchanged(this)">!;
+%                 qq!">!;
 %      } elsif ( $href->{$field}{'type'} eq 'checkbox' ) {
 %        $html .= qq!<INPUT TYPE="checkbox" NAME="$field" VALUE=1 !.
 %                 ( exists($plandata{$field}) && $plandata{$field}
@@ -316,7 +339,7 @@ Line-item revenue recognition
 %        $html .= '<SELECT';
 %        $html .= ' MULTIPLE'
 %          if $href->{$field}{'type'} eq 'select_multiple';
-%        $html .= qq! NAME="$field" onChange="fchanged(this)">!;
+%        $html .= qq! NAME="$field">!;
 %
 %        if ( $href->{$field}{'select_table'} ) {
 %          foreach my $record (
@@ -360,7 +383,7 @@ Line-item revenue recognition
 %             
 %    $html .= '<INPUT TYPE="submit" VALUE="'.
 %             ( $hashref->{pkgpart} ? "Apply changes" : "Add package" ).
-%             '" onClick="fchanged(this)">';
+%             '">';
 %
 %    $html;
 %
index 204c751..1158222 100755 (executable)
 %  $cgi->param($_, '') unless defined $cgi->param($_);
 %}
 %
+%my @agents;
+%foreach ($cgi->param('agent_type')) {
+%  /^(\d+)$/;
+%  push @agents, $1 if $1;
+%}
+%
 %my $new = new FS::part_pkg ( {
 %  map {
 %    $_ => scalar($cgi->param($_));
 %  $pkgpart = $new->pkgpart;
 %}
 %
+%unless ($error) {
+%  my $error = $new->process_m2m(
+%    'link_table'   => 'type_pkgs',
+%    'target_table' => 'agent_type',
+%    'params'       => \@agents,
+%  );
+%}
 %if ( $error ) {
 %  $cgi->param('error', $error );
 %  print $cgi->redirect(popurl(2). "part_pkg.cgi?". $cgi->query_string );
index 0c3c005..3235ef6 100644 (file)
@@ -9,8 +9,11 @@
   <OPTION VALUE=""><% $opt{'empty_label'} || 'all' %>
 
 % foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() } @records ) {
+%   my $matches = 0;
+%   ref($opt{'value'}) ? (exists($opt{'value'}->{$record->$key()}) and $matches=1)
+%                      : ($opt{'value'} == $record->$key() and $matches=1);
 
-    <OPTION VALUE="<% $record->$key() %>"<% $opt{'value'} == $record->$key() ? ' SELECTED' : '' %>><% $record->$name_col() %>
+    <OPTION VALUE="<% $record->$key() %>"<% $matches ? ' SELECTED' : '' %>><% $record->$name_col() %>
 
 % } 
 
@@ -59,6 +62,7 @@ if ( $opt{records} ) {
 }
 
 unless (    ! $opt{value}
+         or ref($opt{value})
          or ! exists( $opt{hashref}->{disabled} ) #??
          or grep { $opt{value} == $_->$key() } @records
        ) {
@@ -72,6 +76,10 @@ unless (    ! $opt{value}
   push @records, $record if $record;
 }
 
+if ( ref( $opt{value} ) eq 'ARRAY' ) {
+  $opt{value} = { map { $_ => 1 } @{$opt{value}} };
+}
+
 my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();
 
 </%init>