From 42132c9a86d36d7fefa7ba5f058f764ba6e7ad5b Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 28 Aug 2008 21:32:26 +0000 Subject: [PATCH] taxproduct selection for one time charges --- FS/FS/cust_main.pm | 22 +++++---- FS/FS/part_pkg.pm | 20 +++++++++ httemplate/browse/part_pkg_taxproduct.cgi | 11 ++++- httemplate/edit/part_pkg_taxoverride.html | 9 +++- httemplate/edit/process/quick-charge.cgi | 13 +++++- httemplate/edit/quick-charge.html | 8 +++- httemplate/elements/select-taxoverride.html | 4 +- httemplate/elements/select-taxproduct.html | 4 +- httemplate/view/cust_main/packages.html | 70 ++++++++++++++++++++++++++++- 9 files changed, 143 insertions(+), 18 deletions(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index b72079cf1..9e501238c 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -4892,6 +4892,7 @@ the error, otherwise returns false. sub charge { my $self = shift; my ( $amount, $quantity, $pkg, $comment, $taxclass, $additional, $classnum ); + my ( $taxproduct, $override ); if ( ref( $_[0] ) ) { $amount = $_[0]->{amount}; $quantity = exists($_[0]->{quantity}) ? $_[0]->{quantity} : 1; @@ -4901,6 +4902,8 @@ sub charge { $taxclass = exists($_[0]->{taxclass}) ? $_[0]->{taxclass} : ''; $classnum = exists($_[0]->{classnum}) ? $_[0]->{classnum} : ''; $additional = $_[0]->{additional}; + $taxproduct = $_[0]->{taxproductnum}; + $override = { '' => $_[0]->{tax_override} }; }else{ $amount = shift; $quantity = 1; @@ -4922,13 +4925,14 @@ sub charge { my $dbh = dbh; my $part_pkg = new FS::part_pkg ( { - 'pkg' => $pkg, - 'comment' => $comment, - 'plan' => 'flat', - 'freq' => 0, - 'disabled' => 'Y', - 'classnum' => $classnum ? $classnum : '', - 'taxclass' => $taxclass, + 'pkg' => $pkg, + 'comment' => $comment, + 'plan' => 'flat', + 'freq' => 0, + 'disabled' => 'Y', + 'classnum' => $classnum ? $classnum : '', + 'taxclass' => $taxclass, + 'taxproductnum' => $taxproduct, } ); my %options = ( ( map { ("additional_info$_" => $additional->[$_] ) } @@ -4938,7 +4942,9 @@ sub charge { 'setup_fee' => $amount, ); - my $error = $part_pkg->insert( options => \%options ); + my $error = $part_pkg->insert( options => \%options, + tax_overrides => $override, + ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 57145fdd9..3eb3bc139 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -144,6 +144,10 @@ record itself), the object will be updated to point to this package definition. In conjunction with I, if I is set to a scalar reference, the scalar will be updated with the custnum value from the cust_pkg record. +If I is set to a hashref with usage classes as keys and comma +separated tax class numbers as values, appropriate FS::part_pkg_taxoverride +records will be inserted. + If I is set to a hashref of options, appropriate FS::part_pkg_option records will be inserted. @@ -191,6 +195,22 @@ sub insert { } } + warn " inserting part_pkg_taxoverride records" if $DEBUG; + my %overrides = %{ $options{'tax_overrides'} || {} }; + foreach my $usage_class ( keys %overrides ) { + my @overrides = (grep "$_", split (',', $overrides{$usage_class}) ); + my $error = $self->process_m2m ( + 'link_table' => 'part_pkg_taxoverride', + 'target_table' => 'tax_class', + 'hashref' => { 'usage_class' => $usage_class }, + 'params' => \@overrides, + ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + warn " inserting pkg_svc records" if $DEBUG; my $pkg_svc = $options{'pkg_svc'} || {}; foreach my $part_svc ( qsearch('part_svc', {} ) ) { diff --git a/httemplate/browse/part_pkg_taxproduct.cgi b/httemplate/browse/part_pkg_taxproduct.cgi index 0cea4f838..7e0cb8191 100755 --- a/httemplate/browse/part_pkg_taxproduct.cgi +++ b/httemplate/browse/part_pkg_taxproduct.cgi @@ -31,6 +31,7 @@ die "access denied" my @menubar; my $title = ''; +my $onclick = 'cClick'; my $data_vendor = ''; if ( $cgi->param('data_vendor') =~ /^(\w+)$/ ) { @@ -54,10 +55,14 @@ my $tax_customer = $1 my $id = $1 if ( $cgi->param('id') =~ /^([ \w]+)$/ ); +$onclick = $1 + if ( $cgi->param('onclick') =~ /^(\w+)$/ ); +$cgi->delete('onclick'); + my $remove_onclick = <description; "parent.document.getElementById('$id').value = $taxnum;". "parent.document.getElementById('${id}_description').value = '$desc';". - "parent.cClick();"; + "parent.$onclick();"; } if $id; @@ -111,6 +116,7 @@ $cgi->param('tax_group', $tax_group) if $tax_group; $cgi->param('tax_item', $tax_item ) if $tax_item; $cgi->param('tax_provider', $tax_provider ) if $tax_provider; $cgi->param('tax_customer', $tax_customer ) if $tax_customer; +$cgi->param('onclick', $onclick ) if $onclick; my $count_query = "SELECT COUNT(*) FROM part_pkg_taxproduct $extra_sql"; @@ -152,6 +158,7 @@ $html_init .= qq(
+ diff --git a/httemplate/edit/part_pkg_taxoverride.html b/httemplate/edit/part_pkg_taxoverride.html index 5f191b373..61dfa2ac5 100644 --- a/httemplate/edit/part_pkg_taxoverride.html +++ b/httemplate/edit/part_pkg_taxoverride.html @@ -10,8 +10,8 @@ @@ -124,4 +124,9 @@ my $selected = $1 my $element_name = $1 if $cgi->param('element_name') =~/^(\w+)$/; +my $onclick = $1 + if $cgi->param('onclick') =~/^(\w+)$/; + +$onclick = 'cClick' unless $onclick; + diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi index 4c4927f4d..839a4e911 100644 --- a/httemplate/edit/process/quick-charge.cgi +++ b/httemplate/edit/process/quick-charge.cgi @@ -14,6 +14,7 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('One-time charge'); my $error = ''; +my $conf = new FS::conf; my $param = $cgi->Vars; my @description = (); @@ -35,8 +36,16 @@ if ( $cgi->param('quantity') =~ /^\s*(\d+)\s*$/ ) { $quantity = $1; } +$param->{'tax_override'} =~ /^\s*([,\d]*)\s*$/ + or $error .= "Illegal tax override " . $param->{"tax_override"} . " "; +my $override = $1; + if ( $param->{'taxclass'} eq '(select)' ) { - $error .= "Must select a tax class. "; + $error .= "Must select a tax class. " + unless ($conf->exists('enable_taxproducts') && + ( $override || $param->{taxproductnum} ) + ); + $cgi->param('taxclass', ''); } unless ( $error ) { @@ -48,6 +57,8 @@ unless ( $error ) { 'quantity' => $quantity, 'pkg' => scalar($cgi->param('pkg')), 'taxclass' => scalar($cgi->param('taxclass')), + 'taxproductnum' => scalar($cgi->param('taxproductnum')), + 'tax_override' => $override, 'classnum' => scalar($cgi->param('classnum')), 'additional' => \@description, } ); diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html index d51015054..bf4c44571 100644 --- a/httemplate/edit/quick-charge.html +++ b/httemplate/edit/quick-charge.html @@ -71,7 +71,7 @@ function validate_quick_charge () { - + @@ -97,6 +97,10 @@ function validate_quick_charge () { <% include('/elements/tr-select-taxclass.html', 'curr_value' => $cgi->param('taxclass') ) %> +<% include('/elements/tr-select-taxproduct.html', 'label' => 'Tax product', 'onclick' => 'parent.taxproductmagic(this);', 'curr_value' => $cgi->param('taxproductnum') ) %> + +<% include('/elements/tr-select-taxoverride.html', 'onclick' => 'parent.taxoverridemagic(this);', 'curr_value' => $cgi->param('tax_override') ) %> + % my $row = 0; -% if ( $cgi->param('error') ) { +% if ( $cgi->param('error') || $cgi->param('magic') ) { % my $param = $cgi->Vars; % % for ( $row = 0; exists($param->{"description$row"}); $row++ ) { diff --git a/httemplate/elements/select-taxoverride.html b/httemplate/elements/select-taxoverride.html index f3bfb5fd7..8b1c528eb 100644 --- a/httemplate/elements/select-taxoverride.html +++ b/httemplate/elements/select-taxoverride.html @@ -3,7 +3,7 @@ TYPE = "hidden" VALUE = "<% $value %>" > - + <% $value ? "Edit $class tax overrides" : "Override $class taxes" %> <%init> @@ -23,4 +23,6 @@ $name =~ /^tax_override_(\w+)$/ && ( $usage = $1 ); my $class = lc($usage_class{$usage} || "Usage class $usage") if $usage; +my $onclick = $opt{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;"; + diff --git a/httemplate/elements/select-taxproduct.html b/httemplate/elements/select-taxproduct.html index 37a428960..0f6ef5583 100644 --- a/httemplate/elements/select-taxproduct.html +++ b/httemplate/elements/select-taxproduct.html @@ -8,7 +8,7 @@ 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'} %> + onClick = "<% $onclick %>"><% $opt{'postfix'} %> <%init> my %opt = @_; @@ -23,4 +23,6 @@ unless ( $description || ! $value ) { if $part_pkg_taxproduct; } +my $onclick = $opt{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;"; + diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html index d8e8130c2..9d5f993cd 100755 --- a/httemplate/view/cust_main/packages.html +++ b/httemplate/view/cust_main/packages.html @@ -1,5 +1,73 @@ Packages
+% if ( $curuser->access_right('One-time charge') ) { + + + + + + + + +% } + % my $s = 0; % if ( $curuser->access_right('Order customer package') ) { <% $s++ ? ' | ' : '' %> @@ -20,8 +88,8 @@ 'width' => 545, }) %> - % } + % if ( $curuser->access_right('Bulk change customer packages') ) { <% $s++ ? ' | ' : '' %> Bulk order and cancel packages (preserves services) -- 2.11.0
- ').value=s.toString(); parent.cClick();"> - + ').value=s.toString(); parent.<% $onclick %>();"> +
Description: @@ -110,7 +114,7 @@ function validate_quick_charge () {