Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / browse / part_pkg_taxproduct / compliance_solutions.html
1 <& /elements/header-popup.html, 'Select tax product' &>
2
3 <& '/elements/xmlhttp.html',
4      'url'  => $fsurl.'misc/xmlhttp-part_pkg_taxproduct.html',
5      'subs' => [ 'get_part_pkg_taxproduct'] &>
6
7 <script>
8
9 $().ready(function() {
10
11
12   $('#taxproduct_submit').on('click', function() {
13     var service_code = $('#service_code').val().split(' ');
14     select_taxproduct(
15       service_code[0],
16       service_code[1] + ' ' + $('#service_code :selected').text()
17     );
18   });
19 });
20
21 // post the values back to the parent form
22 function select_taxproduct(taxproductnum, description) {
23   parent.document.getElementById('<% $id %>').value = taxproductnum;
24   parent.document.getElementById('<% $id %>_description').value = description;
25   parent.cClick();
26 }
27
28 function jopt(what,value,text) {
29   var optionName = new Option(text, value, false, false);
30   what.append(optionName);
31 }
32
33 function category_changed(what) {
34   var category = what.options[what.selectedIndex].value;
35
36   if ( category.length == 0 ) {
37     $('#product_code').empty();
38     $('#service_code').empty();
39     $('#taxproduct_submit').prop('disabled', true);
40     return;
41   }
42
43   get_part_pkg_taxproduct(
44     'data_vendor', 'compliance_solutions', 'category', category,
45     function (data) {
46
47       $('#product_code').empty();
48       $('#service_code').empty();
49       $('#taxproduct_submit').prop('disabled', true);
50
51       var reply = JSON.parse(data);
52
53       jopt( $('#product_code'), '', 'Select product code' );
54
55       var part_pkg_taxproduct = reply.part_pkg_taxproduct;
56       if ( part_pkg_taxproduct.length == 0 ) {
57         alert('No compliance solutions product codes found; did you run freeside-compliance_solutions-import?');
58       }
59       for ( var s = 0; s < part_pkg_taxproduct.length; s=s+2 ) {
60         var product_code = part_pkg_taxproduct[s];
61         var description = part_pkg_taxproduct[s+1];
62         jopt( $('#product_code'), product_code, description );
63       }
64
65     },
66   );
67
68 }
69
70 function product_code_changed(what) {
71   var product_code = what.options[what.selectedIndex].value;
72
73   if ( product_code.length == 0 ) {
74     $('#service_code').empty();
75     $('#taxproduct_submit').prop('disabled', true);
76     return;
77   }
78
79   get_part_pkg_taxproduct(
80     'data_vendor', 'compliance_solutions', 'product_code', product_code,
81     function (data) {
82
83       $('#service_code').empty();
84       $('#taxproduct_submit').prop('disabled', true);
85
86       jopt( $('#service_code'), '', 'Select service code' );
87
88       var reply = JSON.parse(data);
89
90       var part_pkg_taxproduct = reply.part_pkg_taxproduct;
91       for ( var s = 0; s < part_pkg_taxproduct.length; s=s+2 ) {
92         var product_service_code = part_pkg_taxproduct[s];
93         var description = part_pkg_taxproduct[s+1];
94         jopt( $('#service_code'), product_service_code, description );
95       }
96
97     },
98   );
99
100 }
101
102 function service_code_changed(what) {
103   var service_code = what.options[what.selectedIndex].value;
104
105   if ( service_code.length > 0 ) {
106     $('#taxproduct_submit').prop('disabled', false);
107   } else {
108     $('#taxproduct_submit').prop('disabled', true);
109   }
110 }
111
112 </script>  
113
114 <FORM>
115   <% ntable('#cccccc', 2) %>
116
117     <& /elements/tr-select.html,
118          label   => emt('Category'),
119          field   => 'category',
120          id      => 'category',
121          options => [ '', qw( C G N S T V W )],
122          labels  => {
123                       ''  => 'Select category',
124                       'C' => 'COMPUTER',
125                       'G' => 'GENERAL MERCHANDISE',
126                       'N' => 'NON-TAXABLE AND EXEMPT',
127                       'S' => 'SATELLITE',
128                       'T' => 'TELECOM',
129                       'V' => 'VOIP',
130                       'W' => 'WIRELESS',
131                     },
132         onchange => 'category_changed(what);',
133     &>
134
135     <& /elements/tr-select.html,
136         label    => emt('Product code'),
137         field    => 'product_code',
138         id       => 'product_code',
139         onchange => 'product_code_changed(what);',
140     &>
141
142     <& /elements/tr-select.html,
143         label    => emt('Service code'),
144         field    => 'service_code',
145         id       => 'service_code',
146         onchange => 'service_code_changed(what);',
147     &>
148
149   </table>
150   <BR>
151
152   <input type="button" id="taxproduct_submit" value="Select Product" DISABLED>
153 </FORM>
154
155 <& /elements/footer-popup.html &>
156 <%init>
157
158 die "access denied"
159   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
160
161 $cgi->param('id') =~ /^\w+$/ or die "missing id parameter";
162 my $id = $cgi->param('id');
163
164 my $hashref = { data_vendor => 'compliance_solutions' };
165
166 </%init>