diff options
author | jeff <jeff> | 2008-08-28 21:32:26 +0000 |
---|---|---|
committer | jeff <jeff> | 2008-08-28 21:32:26 +0000 |
commit | 42132c9a86d36d7fefa7ba5f058f764ba6e7ad5b (patch) | |
tree | cc02b304e583dd1a10d09f300cc15c56e5863a65 | |
parent | f0d52fc82b138598228c401d99b56e88366c6945 (diff) |
taxproduct selection for one time charges
-rw-r--r-- | FS/FS/cust_main.pm | 22 | ||||
-rw-r--r-- | FS/FS/part_pkg.pm | 20 | ||||
-rwxr-xr-x | httemplate/browse/part_pkg_taxproduct.cgi | 11 | ||||
-rw-r--r-- | httemplate/edit/part_pkg_taxoverride.html | 9 | ||||
-rw-r--r-- | httemplate/edit/process/quick-charge.cgi | 13 | ||||
-rw-r--r-- | httemplate/edit/quick-charge.html | 8 | ||||
-rw-r--r-- | httemplate/elements/select-taxoverride.html | 4 | ||||
-rw-r--r-- | httemplate/elements/select-taxproduct.html | 4 | ||||
-rwxr-xr-x | 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<cust_pkg>, if I<custnum_ref> is set to a scalar reference, the scalar will be updated with the custnum value from the cust_pkg record. +If I<tax_overrides> 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<options> 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 = <<EOS parent.document.getElementById('$id').value = ''; parent.document.getElementById('${id}_description').value = ''; - parent.cClick(); + parent.$onclick(); EOS if $id; @@ -67,7 +72,7 @@ my $select_onclick = sub { my $desc = $row->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( <FORM> <INPUT NAME="_type" TYPE="hidden" VALUE="$type"> <INPUT NAME="taxproductnum" TYPE="hidden" VALUE="$taxproductnum"> + <INPUT NAME="onclick" TYPE="hidden" VALUE="$onclick"> <INPUT NAME="id" TYPE="hidden" VALUE="$id"> <TABLE> <TR> 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 @@ <TR><TD> <FORM="dummy"> <CENTER> - <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();"> + <INPUT type="submit" value="Finish" onclick="s=fetchSelected(); s.shift(); parent.document.getElementById('<% $element_name || "tax_override" %>').value=s.toString(); parent.<% $onclick %>();"> + <INPUT type="reset" value="Cancel" onclick="parent.<% $onclick %>();"> </CENTER> </FORM> </TD></TR> @@ -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; + </%init> 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 () { </SCRIPT> -<FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();"> +<FORM ACTION="process/quick-charge.cgi" NAME="QuickChargeForm" ID="QuickChargeForm" METHOD="POST" onsubmit="document.QuickChargeForm.submit.disabled=true;return validate_quick_charge();"> <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>"> @@ -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') ) %> + <TR> <TD>Description:</TD> <TD> @@ -110,7 +114,7 @@ function validate_quick_charge () { </TR> % 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 %>" > - <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;"> + <A href="javascript:void(0)" onclick="<% $onclick %>"> <% $value ? "Edit $class tax overrides" : "Override $class taxes" %> </A> <%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;"; + </%init> 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;"; + </%init> 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 @@ <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR> +% if ( $curuser->access_right('One-time charge') ) { + +<SCRIPT TYPE="text/javascript"> + +function taxproductmagic(which) { + var str = ''; + var elements = which.form.elements; + for (var i = 0; i<elements.length; i++) { + if (elements[i].name == 'taxproductnum'){ + document.getElementById('taxproductnum').value = elements[i].value; + continue; + } + if (elements[i].name == 'taxproductnum_description'){ + continue; + } + if (str.length){str += ';';} + str += elements[i].name + '=' + escape(elements[i].value); + } + document.getElementById('charge_storage').value = str; + cClick(); + overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&onclick=taxproductquickchargemagic&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); +} + +function taxproductquickchargemagic() { + var str = document.getElementById('charge_storage').value; + if (str.length){str += ';';} + str += 'magic=taxproductnum;taxproductnum='; + str += escape(document.getElementById('taxproductnum').value); + cClick(); + overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close'); + +} + +function taxoverridemagic(which) { + var str = ''; + var elements = which.ownerDocument.QuickChargeForm.elements; + for (var i = 0; i<elements.length; i++) { + if (elements[i].name == 'tax_override'){ + document.getElementById('tax_override').value = elements[i].value; + continue; + } + if (str.length){str += ';';} + str += elements[i].name + '=' + escape(elements[i].value); + } + document.getElementById('charge_storage').value = str; + cClick(); + overlib( OLiframeContent('<% $p %>/edit/part_pkg_taxoverride.html?element_name=tax_override;onclick=taxoverridequickchargemagic;selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK); +} + +function taxoverridequickchargemagic() { + var str = document.getElementById('charge_storage').value; + if (str.length){str += ';';} + str += 'magic=taxoverride;tax_override='; + str += document.getElementById('tax_override').value; + cClick(); + overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close'); + +} + +</SCRIPT> +<FORM NAME='quickcharge'> + <INPUT NAME="taxproductnum" ID="taxproductnum" TYPE="hidden"> + <INPUT NAME="tax_override" ID="tax_override" TYPE="hidden"> + <INPUT NAME="charge_storage" ID="charge_storage" TYPE="hidden"> + <INPUT NAME="taxproductnum_description" ID="taxproductnum_description" TYPE="hidden"> +</FORM> +% } + % 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++ ? ' | ' : '' %> <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services) |