summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorjeff <jeff>2008-08-28 07:38:40 +0000
committerjeff <jeff>2008-08-28 07:38:40 +0000
commit669bd6b315633c99ac61441198c2c4e45401c36b (patch)
treeaf72b9ad7bf116b147700f63f5b2895b0c9c9e5b /httemplate
parent2c37cd91ea7951b70ea5d420e989128d78ce0a80 (diff)
multiple usage classes checkpoint
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/browse/part_pkg_taxproduct.cgi12
-rwxr-xr-xhttemplate/edit/part_pkg.cgi107
-rw-r--r--httemplate/edit/part_pkg_taxoverride.html5
-rwxr-xr-xhttemplate/edit/process/part_pkg.cgi23
-rw-r--r--httemplate/elements/select-taxoverride.html26
-rw-r--r--httemplate/elements/select-taxproduct.html44
-rw-r--r--httemplate/elements/tr-select-taxoverride.html18
-rw-r--r--httemplate/elements/tr-select-taxproduct.html18
8 files changed, 210 insertions, 43 deletions
diff --git a/httemplate/browse/part_pkg_taxproduct.cgi b/httemplate/browse/part_pkg_taxproduct.cgi
index 3df819715..0cea4f838 100755
--- a/httemplate/browse/part_pkg_taxproduct.cgi
+++ b/httemplate/browse/part_pkg_taxproduct.cgi
@@ -54,6 +54,13 @@ my $tax_customer = $1
my $id = $1
if ( $cgi->param('id') =~ /^([ \w]+)$/ );
+my $remove_onclick = <<EOS
+ parent.document.getElementById('$id').value = '';
+ parent.document.getElementById('${id}_description').value = '';
+ parent.cClick();
+EOS
+ if $id;
+
my $select_onclick = sub {
my $row = shift;
my $taxnum = $row->taxproductnum;
@@ -132,7 +139,10 @@ my @fields = (
my $html_init = '';
-$html_init = '<TABLE><TR><TD>Current tax product: </TD><TD>'.
+my $select_link = [ 'javascript:void(0);', sub { ''; } ];
+$html_init = '<TABLE><TR><TD><A HREF="javascript:void(0)" '.
+ qq!onClick="$remove_onclick">(remove)</A>&nbsp;!.
+ 'Current tax product: </TD><TD>'.
$selected_part_pkg_taxproduct->description.
'</TD></TR></TABLE><BR><BR>'
if $selected_part_pkg_taxproduct;
diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
index d10a09a5a..3968c8913 100755
--- a/httemplate/edit/part_pkg.cgi
+++ b/httemplate/edit/part_pkg.cgi
@@ -23,6 +23,7 @@
'setuptax' => 'Setup fee tax exempt',
'recurtax' => 'Recurring fee tax exempt',
'taxclass' => 'Tax class',
+ 'taxproduct_select'=> 'Tax products',
'plan' => 'Price plan',
'disabled' => 'Disable new orders',
'pay_weight' => 'Payment weight',
@@ -82,7 +83,21 @@
{field=>'setuptax', type=>'checkbox', value=>'Y'},
{field=>'recurtax', type=>'checkbox', value=>'Y'},
{field=>'taxclass', type=>'select-taxclass' },
- {field=>'taxproductnum', type=>'select-taxproduct' },
+ { field => 'taxproductnums',
+ type => 'hidden',
+ value => join(',', @taxproductnums),
+ },
+ { field => 'taxproduct_select',
+ type => 'selectlayers',
+ options => [ '(default)', @taxproductnums ],
+ curr_value => '(default)',
+ labels => { ( '(default)' => '(default)' ),
+ map {($_=>$usage_class{$_})}
+ @taxproductnums
+ },
+ layer_fields => \%taxproduct_fields,
+ layer_values_callback => $taxproduct_values,
+ },
{ type => 'tablebreak-tr-title',
value => 'Promotions', #better name?
@@ -164,16 +179,41 @@ die "access denied"
#my $part_pkg = '';
my @agent_type = ();
-my $tax_override;
+my %tax_override = ();
my $clone_part_pkg = '';
+my %taxproductnums = map { ($_->classnum => 1) }
+ qsearch('usage_class', { 'disabled' => '' });
+
+if ( $cgi->param('error') ) { # oh well
+ foreach ($cgi->param) {
+ /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
+ }
+} elsif ( my $pkgpart = $cgi->keywords || $cgi->param('pkgpart') ) {
+ $pkgpart =~ /^(\d+)$/ or die "illegal pkgpart";
+ my $part_pkg = qsearchs( 'part_pkg', { pkgpart => $pkgpart } );
+ die "no part_pkg for pkgpart $pkgpart" unless $pkgpart;
+ foreach ($part_pkg->options) {
+ /^usage_taxproductnum_(\d+)$/ && ($taxproductnums{$1} = 1);
+ }
+ foreach ($part_pkg->part_pkg_taxoverride) {
+ $taxproductnums{$_->usage_class} = 1
+ if $_->usage_class;
+ }
+} else {
+ # do nothing
+}
+my @taxproductnums = ( qw( setup recur ), sort (keys %taxproductnums) );
+
my %options = ();
my $recur_disabled = 1;
my $error_callback = sub {
my($cgi, $object, $fields, $opt ) = @_;
(@agent_type) = $cgi->param('agent_type');
- $tax_override = $cgi->param('tax_override');
+ $tax_override{''} = $cgi->param('tax_override');
+ $tax_override{$_} = $cgi->param('tax_override_$_')
+ foreach(grep { /^tax_override_(\w+)$/ } $cgi->param);
$opt->{action} = 'Custom' if $cgi->param('clone');
$clone_part_pkg= qsearchs('part_pkg', { 'pkgpart' => $cgi->param('clone') } );
@@ -223,15 +263,19 @@ my $new_object_callback = sub {
};
my $edit_callback = sub {
- my( $cgi, $object, $fields ) = @_;
+ my( $cgi, $object, $fields, $opt ) = @_;
$recur_disabled = $object->freq ? 0 : 1;
(@agent_type) = map {$_->typenum} qsearch('type_pkgs',{'pkgpart'=>$1});
- $tax_override =
+ $tax_override{$_} =
join (",", map {$_->taxclassnum}
- qsearch( 'part_pkg_taxoverride', {'pkgpart' => $1} )
- );
+ qsearch( 'part_pkg_taxoverride', { 'pkgpart' => $object->pkgpart,
+ 'usage_class' => $_,
+ }
+ )
+ )
+ foreach ( '', @taxproductnums );
# join (",", map {$_->taxclassnum}
# $part_pkg->part_pkg_taxrate( 'cch', $conf->config('defaultloc')
@@ -432,8 +476,57 @@ my $html_bottom = sub {
include('/elements/selectlayers.html', %selectlayers, 'layers_only'=>1 ).
'<SCRIPT TYPE="text/javascript">'.
include('/elements/selectlayers.html', %selectlayers, 'js_only'=>1 ).
+ "taxproduct_selectchanged(document.getElementById('taxproduct_select'));".
'</SCRIPT>';
};
+my %usage_class = map { ($_->classnum => $_->classname) }
+ qsearch('usage_class', {});
+$usage_class{setup} = 'Setup';
+$usage_class{recur} = 'Recurring';
+
+my %taxproduct_fields = map { $_ => [ "taxproductnum_$_",
+ { type => 'select-taxproduct',
+ #label => "$usage_class{$_} tax product",
+ },
+ "tax_override_$_",
+ { type => 'select-taxoverride' }
+ ]
+ }
+ @taxproductnums;
+$taxproduct_fields{'(default)'} =
+ [ 'taxproductnum', { type => 'select-taxproduct',
+ #label => 'Default tax product',
+ },
+ 'tax_override', { type => 'select-taxoverride' },
+ ];
+
+my $taxproduct_values = sub {
+ my ($cgi, $object, $flags) = @_;
+ my $routine =
+ sub { my $layer = shift;
+ my @fields = @{$taxproduct_fields{$layer}};
+ my @values = ();
+ while( @fields ) {
+ my $field = shift @fields;
+ shift @fields;
+ $field =~ /^taxproductnum_\w+$/ &&
+ push @values, ( $field => $options{"usage_$field"} );
+ $field =~ /^tax_override_(\w+)$/ &&
+ push @values, ( $field => $tax_override{$1} );
+ $field =~ /^taxproductnum$/ &&
+ push @values, ( $field => $object->taxproductnum );
+ $field =~ /^tax_override$/ &&
+ push @values, ( $field => $tax_override{''} );
+ }
+ { (@values) };
+ };
+
+ my @result =
+ map { ( $_ => { &{$routine}($_) } ) } ( '(default)', @taxproductnums );
+ return({ @result });
+
+};
+
</%init>
diff --git a/httemplate/edit/part_pkg_taxoverride.html b/httemplate/edit/part_pkg_taxoverride.html
index ba709ce64..5f191b373 100644
--- a/httemplate/edit/part_pkg_taxoverride.html
+++ b/httemplate/edit/part_pkg_taxoverride.html
@@ -10,7 +10,7 @@
<TR><TD>
<FORM="dummy">
<CENTER>
- <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('tax_override').value=s.toString(); parent.cClick();">
+ <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('<% $element_name || "tax_override" %>').value=s.toString(); parent.cClick();">
<INPUT type="reset" value="Cancel" onclick="parent.cClick();">
</CENTER>
</FORM>
@@ -121,4 +121,7 @@ my $unselected_offset = $1
my $selected = $1
if $cgi->param('selected') =~/^([,\d]+)$/;
+my $element_name = $1
+ if $cgi->param('element_name') =~/^(\w+)$/;
+
</%init>
diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi
index 91ae97132..d338b8299 100755
--- a/httemplate/edit/process/part_pkg.cgi
+++ b/httemplate/edit/process/part_pkg.cgi
@@ -84,6 +84,13 @@ my $args_callback = sub {
}
@options;
+ foreach ( split(',', $cgi->param('taxproductnums') ) ) {
+ my $value = $cgi->param("taxproductnum_$_");
+ $error ||= "Illegal taxproductnum_$_: $value"
+ unless ( $value =~ /^\d*$/ );
+ $options{"usage_taxproductnum_$_"} = $value;
+ }
+
$options{$_} = scalar( $cgi->param($_) )
for (qw( setup_fee recur_fee ));
@@ -146,6 +153,22 @@ my @process_m2m = (
},
);
+foreach my $override_class ($cgi->param) {
+ next unless $override_class =~ /^tax_override_(\w+)$/;
+ my $class = $1;
+
+ my (@tax_overrides) = (grep "$_", split (",", $1))
+ if $cgi->param($override_class) =~ /^([\d,]+)$/;
+
+ push @process_m2m, {
+ 'link_table' => 'part_pkg_taxoverride',
+ 'target_table' => 'tax_class',
+ 'hashref' => { 'usage_class' => $class },
+ 'params' => \@tax_overrides,
+ };
+
+}
+
my $conf = new FS::Conf;
if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
diff --git a/httemplate/elements/select-taxoverride.html b/httemplate/elements/select-taxoverride.html
new file mode 100644
index 000000000..f3bfb5fd7
--- /dev/null
+++ b/httemplate/elements/select-taxoverride.html
@@ -0,0 +1,26 @@
+ <INPUT NAME = "<% $name %>"
+ ID = "<% $name %>"
+ TYPE = "hidden"
+ VALUE = "<% $value %>"
+ >
+ <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?element_name=<% $name %>;selected='+document.getElementById('<% $name %>').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit <% $class %> product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
+ <% $value ? "Edit $class tax overrides" : "Override $class taxes" %>
+ </A>
+<%init>
+
+my %opt = @_;
+my $name = $opt{element_name} || $opt{field} || 'tax_override';
+my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
+
+my %usage_class = map { ($_->classnum => $_->classname) }
+ qsearch('usage_class', {});
+$usage_class{setup} = 'Setup';
+$usage_class{recur} = 'Recurring';
+
+my $usage;
+$name =~ /^tax_override_(\w+)$/ && ( $usage = $1 );
+
+my $class = lc($usage_class{$usage} || "Usage class $usage")
+ if $usage;
+
+</%init>
diff --git a/httemplate/elements/select-taxproduct.html b/httemplate/elements/select-taxproduct.html
index 74044b108..37a428960 100644
--- a/httemplate/elements/select-taxproduct.html
+++ b/httemplate/elements/select-taxproduct.html
@@ -1,28 +1,26 @@
-<% ntable("#cccccc", 2) %>
- <TR>
- <TD align="right">Tax product</TD>
- <TD>
- <INPUT name="taxproductnum" id="taxproductnum" type="hidden" value="<% $opt{'taxproductnum'}%>">
- <INPUT name="taxproductnum_description" id="taxproductnum_description" type="text" value="<% $opt{taxproduct_description} %>" size="12" onclick="overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
- </TD>
- </TR>
- <TR>
- <TD colspan="2" align="right">
- <INPUT name="tax_override" id="tax_override" type="hidden" value="<% $opt{tax_override} %>">
- <A href="javascript:void(0)" onclick="overlib( OLiframeContent('part_pkg_taxoverride.html?selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;">
- <% $opt{tax_override} ? 'Edit tax overrides' : 'Override taxes' %>
- </A>
- </TD>
- </TR>
-</TABLE>
-
+<% $opt{'prefix'} %><INPUT NAME = "<% $name %>"
+ ID = "<% $name %>"
+ TYPE = "hidden"
+ VALUE = "<% $value |h %>"
+ >
+ <INPUT NAME = "<% $name %>_description"
+ ID = "<% $name %>_description"
+ TYPE = "text"
+ VALUE = "<% $description %>"
+ SIZE = "12"
+ onclick = "overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=<% $name %>&taxproductnum='+document.getElementById('<% $name %>').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); return false;"><% $opt{'postfix'} %>
<%init>
my %opt = @_;
-
-$opt{'taxproductnum'} ||= $opt{'object'}->taxproductnum
- if $opt{'object'};
-$opt{'taxproduct_description'} ||= $opt{'object'}->taxproduct_description
- if $opt{'object'};
+my $name = $opt{element_name} || $opt{field} || 'taxproductnum';
+my $value = length($opt{curr_value}) ? $opt{curr_value} : $opt{value};
+my $description = $opt{'taxproduct_description'};
+
+unless ( $description || ! $value ) {
+ my $part_pkg_taxproduct =
+ qsearchs( 'part_pkg_taxproduct', { 'taxproductnum'=> $value } );
+ $description = $part_pkg_taxproduct->description
+ if $part_pkg_taxproduct;
+}
</%init>
diff --git a/httemplate/elements/tr-select-taxoverride.html b/httemplate/elements/tr-select-taxoverride.html
new file mode 100644
index 000000000..4954a5566
--- /dev/null
+++ b/httemplate/elements/tr-select-taxoverride.html
@@ -0,0 +1,18 @@
+% if ( $conf->exists('enable_taxproducts') ) {
+ <%include('tr-td-label.html', @_) %>
+ <TD <% $cell_style %>><% include('select-taxoverride.html', @_) %></TD>
+ </TR>
+
+% } else {
+ <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $opt{value} %>">
+% }
+
+<%init>
+
+my $conf = new FS::conf;
+
+my %opt = @_;
+my $cell_style = $opt{'cell_style'}? 'STYLE="'. $opt{cell_style}. '"' : '';
+my $name = $opt{name} || 'tax_override';
+
+</%init>
diff --git a/httemplate/elements/tr-select-taxproduct.html b/httemplate/elements/tr-select-taxproduct.html
index f9f192a28..951222475 100644
--- a/httemplate/elements/tr-select-taxproduct.html
+++ b/httemplate/elements/tr-select-taxproduct.html
@@ -1,22 +1,18 @@
% if ( $conf->exists('enable_taxproducts') ) {
-
- <TR>
- <TD COLSPAN="2">
- <% include('select-taxproduct.html', @_) %>
- </TD>
- </TR>
+ <%include('tr-td-label.html', @_) %>
+ <TD <% $cell_style %>><% include('select-taxproduct.html', @_) %></TD>
+ </TR>
% } else {
-
- <INPUT TYPE="hidden" NAME="taxproductnum" VALUE="<% $opt{taxproductnum} %>">
- <INPUT TYPE="hidden" NAME="tax_override" VALUE="<% $opt{tax_override} %>">
-
+ <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $opt{value} %>">
% }
<%init>
-my $conf = new FS::Conf;
+my $conf = new FS::conf;
my %opt = @_;
+my $cell_style = $opt{cell_style} ? 'STYLE="'. $opt{cell_style}. '"' : '';
+my $name = $opt{name} || 'taxproductnum';
</%init>