discounts, RT#6679
[freeside.git] / httemplate / edit / process / cust_pkg_discount.html
1 % if ($error) {
2 %   $cgi->param('error', $error);
3 %   $cgi->redirect(popurl(3). 'edit/cust_pkg_discount.html?'. $cgi->query_string );
4 % } else {
5
6     <% header("Discount applied") %>
7       <SCRIPT TYPE="text/javascript">
8         window.top.location.reload();
9       </SCRIPT>
10     </BODY>
11     </HTML>
12
13 % }
14 <%init>
15
16 my $curuser = $FS::CurrentUser::CurrentUser;
17
18 die "access denied"
19   unless $curuser->access_right('Discount customer package');
20
21 #this search is really for security wrt agent virt...
22 #maybe move it to the cust_pkg_discount->insert call?
23 my $cust_pkg = qsearchs({
24   #'select'    => 'cust_pkg.*',
25   'table'     => 'cust_pkg',
26   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
27   'hashref'   => { 'pkgnum' => scalar($cgi->param('pkgnum')), },
28   'extra_sql' => ' AND '. $curuser->agentnums_sql,
29 });
30 die 'unknown pkgnum' unless $cust_pkg;
31
32 #XXX something not unlike this for custom discounts
33 #if ( $cgi->param('locationnum') == -1 ) {
34 #  my $cust_location = new FS::cust_location {
35 #    'custnum' => $cust_pkg->custnum,
36 #    map { $_ => scalar($cgi->param($_)) }
37 #        qw( address1 address2 city county state zip country )
38 #  };
39 #  $change{'cust_location'} = $cust_location;
40 #}
41
42 my $cust_pkg_discount = new FS::cust_pkg_discount {
43   'pkgnum'      => $cust_pkg->pkgnum,
44   'discountnum' => scalar($cgi->param('discountnum')),
45   'months_used' => 0,
46   'end_date'    => '', #XXX
47   'otaker'      => $curuser->username,
48 };
49 my $error = $cust_pkg_discount->insert;
50
51 </%init>