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