tax engine refactoring for Avalara and Billsoft tax vendors, #25718
[freeside.git] / httemplate / browse / part_pkg_taxproduct / avalara.html
1 <& /elements/header-popup.html, { title => 'Select tax product' } &>
2 <form NAME="myform">
3 <table class="inv" width="100%">
4 <& /elements/tr-select-table.html,
5   'label'           => 'Tax product',
6   'field'           => 'taxproductnum',
7   'table'           => 'part_pkg_taxproduct',
8   'hashref'         => { data_vendor => 'avalara' },
9   'name_col'        => 'taxproduct', # for sorting
10   'label_callback'  => $label_callback,
11   'curr_value'      => $taxproductnum,
12   'empty_label'     => 'none',
13   'onchange'        => 'select_onchange',
14 &>
15 </table>
16 <table class="inv" width="100%">
17 <tr>
18   <td style="border-top: 1px solid #7e0079; text-align: center" colspan=2>
19   Add a new tax product</td>
20 </tr>
21 <tr>
22   <td style="text-align: right">Avalara tax code</td>
23   <td><input name="taxproduct" size=8></td>
24 </tr>
25 <tr>
26   <td style="text-align: right">Description</td>
27   <td><input name="description" size=20></td>
28 </tr>
29 <tr>
30   <td colspan="2" style="text-align: center">
31     <input type="button" onclick="add_new()" value="Add" />
32   </td>
33 </tr>
34 </table>
35 </form>
36 <SCRIPT TYPE="text/javascript">
37 function select_onchange() {
38   var select = document.forms['myform']['taxproductnum'];
39   parent.document.getElementById('<% $id %>').value = select.value;
40   parent.document.getElementById('<% $id %>_description').value =
41     select.options[select.selectedIndex].text;
42   parent.nd(1);
43 }
44 function add_new() {
45   parent.document.getElementById('<% $id %>').value = -1;
46   parent.document.getElementById('<% $id %>_description').value =
47     document.forms['myform']['taxproduct'].value + ' ' +
48     document.forms['myform']['description'].value;
49   parent.nd(1);
50 }
51 </SCRIPT>
52 </BODY>
53 </HTML>
54 <%once>
55
56 my $conf = new FS::Conf;
57
58 </%once>
59 <%init>
60
61 die "access denied"
62   unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions');
63
64 warn Dumper({ $cgi->Vars });
65
66 # id: where to put the taxproductnum (in the parent document) after the user 
67 # selects it
68 $cgi->param('id') =~ /^([ \w]+)$/
69   or die "id parameter required";
70 my $id = $1;
71
72 # current value of taxproductnum
73 my $taxproductnum = '';
74 if ($cgi->param('taxproductnum') =~ /^(\d+)$/) {
75   $taxproductnum = $1;
76 }
77
78 my $label_callback = sub {
79   my $part_pkg_taxproduct = shift;
80   join(' ', $part_pkg_taxproduct->taxproduct,
81             $part_pkg_taxproduct->description);
82 };
83
84 </%init>