<% include( 'elements/edit.html',
- 'post_url' => popurl(1).'process/part_pkg.cgi',
- 'name' => "Package definition",
- 'table' => 'part_pkg',
-
- 'agent_virt' => 1,
- 'agent_null_right' => $edit_global,
-
- #'viewall_dir' => 'browse',
- 'viewall_url' => $p.'browse/part_pkg.cgi',
- 'html_init' => include('/elements/init_overlib.html').
- $freq_changed,
- 'html_bottom' => $html_bottom,
-
- 'begin_callback' => $begin_callback,
- 'end_callback' => $end_callback,
- 'new_hashref_callback' => $new_hashref_callback,
- 'new_object_callback' => $new_object_callback,
- 'new_callback' => $new_callback,
- 'clone_callback' => $clone_callback,
- 'edit_callback' => $edit_callback,
- 'error_callback' => $error_callback,
+ 'post_url' => popurl(1).'process/part_pkg.cgi',
+ 'name' => "Package definition",
+ 'table' => 'part_pkg',
+
+ 'agent_virt' => 1,
+ 'agent_null_right' => $edit_global,
+ 'agent_clone_extra_sql' => $agent_clone_extra_sql,
+ #'viewall_dir' => 'browse',
+ 'viewall_url' => $p.'browse/part_pkg.cgi',
+ 'html_init' => include('/elements/init_overlib.html').
+ $javascript,
+ 'html_bottom' => $html_bottom,
+ 'body_etc' =>
+ 'onLoad="agent_changed(document.edit_topform.agentnum)"',
+
+ 'begin_callback' => $begin_callback,
+ 'end_callback' => $end_callback,
+ 'new_hashref_callback' => $new_hashref_callback,
+ 'new_object_callback' => $new_object_callback,
+ 'new_callback' => $new_callback,
+ 'clone_callback' => $clone_callback,
+ 'edit_callback' => $edit_callback,
+ 'error_callback' => $error_callback,
+ 'field_callback' => $field_callback,
'labels' => {
'pkgpart' => 'Package Definition',
type => 'select-agent',
disable_empty => ! $acl_edit_global,
empty_label => '(global)',
+ onchange => 'agent_changed',
},
{field=>'classnum', type=>'select-pkg_class' },
{field=>'disabled', type=>$disabled_type, value=>'Y'},
my $disabled_type = $acl_edit_either ? 'checkbox' : 'hidden';
+my $agent_clone_extra_sql =
+ ' ( '. FS::part_pkg->curuser_pkgs_sql.
+ #kludge to clone custom customer packages you otherwise couldn't see
+ " OR ( part_pkg.disabled = 'Y' AND part_pkg.comment LIKE '(CUSTOM)%' ) ".
+ ' ) ';
+
my $conf = new FS::Conf;
my $taxproducts = $conf->exists('enable_taxproducts');
my %taxproductnums = map { ($_->classnum => 1) }
qsearch('usage_class', { 'disabled' => '' });
+my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
my %options = ();
my $recur_disabled = 1;
(@agent_type) = $cgi->param('agent_type');
- $opt->{action} = 'Custom' if $cgi->param('clone');
+ $opt->{action} = 'Custom' if $cgi->param('pkgnum');
$recur_disabled = $cgi->param('freq') ? 0 : 1;
my $clone_callback = sub {
my( $cgi, $object, $fields, $opt ) = @_;
- $opt->{action} = 'Custom';
+ if ( $cgi->param('pkgnum') ) {
+
+ my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cgi->param('pkgnum') } );
+ $object->agentnum( $cust_pkg->cust_main->agentnum );
+
+ $opt->{action} = 'Custom';
+
+ #my $part_pkg = $clone_part_pkg->clone;
+ #this is all clone did anyway
+ $object->comment( '(CUSTOM) '. $object->comment )
+ unless $object->comment =~ /^\(CUSTOM\) /;
- #my $part_pkg = $clone_part_pkg->clone;
- #this is all clone did anyway
- $object->comment( '(CUSTOM) '. $object->comment )
- unless $object->comment =~ /^\(CUSTOM\) /;
+ $object->disabled('Y');
- $object->disabled('Y');
+ }
%options = $object->options;
};
};
-my $freq_changed = <<'END';
+my $javascript = <<'END';
<SCRIPT TYPE="text/javascript">
function freq_changed(what) {
}
+ function agent_changed(what) {
+
+ var agentnum = what.options[what.selectedIndex].value;
+
+ if ( agentnum == 0 ) {
+ what.form.agent_type.disabled = false;
+ //what.form.agent_type.style.backgroundColor = '#ffffff';
+ what.form.agent_type.style.visibility = '';
+ } else {
+ what.form.agent_type.disabled = true;
+ //what.form.agent_type.style.backgroundColor = '#dddddd';
+ what.form.agent_type.style.visibility = 'hidden';
+ }
+
+ }
+
</SCRIPT>
END
$usage_class{setup} = 'Setup';
$usage_class{recur} = 'Recurring';
-my @taxproductnums = ();
my %taxproduct_fields = ();
my $end_callback = sub {
my( $cgi, $object, $fields, $opt ) = @_;
};
+my $field_callback = sub {
+ my ($cgi, $object, $fieldref) = @_;
+
+ my $field = $fieldref->{field};
+ if ($field eq 'taxproductnums') {
+ $fieldref->{value} = join(',', @taxproductnums);
+ } elsif ($field eq 'taxproduct_select') {
+ $fieldref->{options} = [ '(default)', @taxproductnums ];
+ $fieldref->{labels} = { ( '(default)' => '(default)' ),
+ map {( $_ => ($usage_class{$_} || $_) )}
+ @taxproductnums
+ };
+ $fieldref->{layer_fields} = \%taxproduct_fields;
+ $fieldref->{layer_values_callback} = $taxproduct_values;
+ }
+};
+
</%init>