bugfixes; fields isn't exported by derived classes
[freeside.git] / htdocs / edit / process / part_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: part_pkg.cgi,v 1.5 1998-12-30 23:03:29 ivan Exp $
4 #
5 # process/part_pkg.cgi: Edit package definitions (process form)
6 #
7 # ivan@sisd.com 97-dec-10
8 #
9 # don't update non-changing records in part_svc (causing harmless but annoying
10 # "Records identical" errors). ivan@sisd.com 98-feb-19
11 #
12 # Changes to allow page to work at a relative position in server
13 #       bmccane@maxbaud.net     98-apr-3
14 #
15 # Added `|| 0 ' when getting quantity off web page ivan@sisd.com 98-jun-4
16 #
17 # lose background, FS::CGI ivan@sisd.com 98-sep-2
18 #
19 # $Log: part_pkg.cgi,v $
20 # Revision 1.5  1998-12-30 23:03:29  ivan
21 # bugfixes; fields isn't exported by derived classes
22 #
23 # Revision 1.4  1998/12/17 08:40:24  ivan
24 # s/CGI::Request/CGI.pm/; etc
25 #
26 # Revision 1.3  1998/11/21 07:17:58  ivan
27 # bugfix to work for regular aswell as custom pricing
28 #
29 # Revision 1.2  1998/11/15 13:16:15  ivan
30 # first pass as per-user custom pricing
31 #
32
33 use strict;
34 use CGI;
35 use CGI::Carp qw(fatalsToBrowser);
36 use FS::UID qw(cgisuidsetup);
37 use FS::CGI qw(eidiot popurl);
38 use FS::Record qw(qsearch qsearchs fields);
39 use FS::part_pkg;
40 use FS::pkg_svc;
41 use FS::cust_pkg;
42
43 my($cgi)=new CGI;
44 &cgisuidsetup($cgi);
45
46 my($pkgpart)=$cgi->param('pkgpart');
47
48 my($old)=qsearchs('part_pkg',{'pkgpart'=>$pkgpart}) if $pkgpart;
49
50 my($new)=create FS::part_pkg ( {
51   map {
52     $_, scalar($cgi->param($_));
53   } fields('part_pkg')
54 } );
55
56 local $SIG{HUP} = 'IGNORE';
57 local $SIG{INT} = 'IGNORE';
58 local $SIG{QUIT} = 'IGNORE';
59 local $SIG{TERM} = 'IGNORE';
60 local $SIG{TSTP} = 'IGNORE';
61
62 if ( $pkgpart ) {
63   my($error)=$new->replace($old);
64   eidiot($error) if $error;
65 } else {
66   my($error)=$new->insert;
67   eidiot($error) if $error;
68   $pkgpart=$new->getfield('pkgpart');
69 }
70
71 my($part_svc);
72 foreach $part_svc (qsearch('part_svc',{})) {
73 # don't update non-changing records in part_svc (causing harmless but annoying
74 # "Records identical" errors). ivan@sisd.com 98-jan-19
75   #my($quantity)=$cgi->param('pkg_svc'. $part_svc->getfield('svcpart')),
76   my($quantity)=$cgi->param('pkg_svc'. $part_svc->svcpart) || 0,
77   my($old_pkg_svc)=qsearchs('pkg_svc',{
78     'pkgpart'  => $pkgpart,
79     'svcpart'  => $part_svc->getfield('svcpart'),
80   });
81   my($old_quantity)=$old_pkg_svc ? $old_pkg_svc->quantity : 0;
82   next unless $old_quantity != $quantity; #!here
83   my($new_pkg_svc)=create FS::pkg_svc({
84     'pkgpart'  => $pkgpart,
85     'svcpart'  => $part_svc->getfield('svcpart'),
86     #'quantity' => $cgi->param('pkg_svc'. $part_svc->getfield('svcpart')),
87     'quantity' => $quantity, 
88   });
89   if ($old_pkg_svc) {
90     my($error)=$new_pkg_svc->replace($old_pkg_svc);
91     eidiot($error) if $error;
92   } else {
93     my($error)=$new_pkg_svc->insert;
94     eidiot($error) if $error;
95   }
96 }
97
98 unless ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
99   print $cgi->redirect(popurl(3). "browse/part_pkg.cgi");
100 } else {
101   my($old_cust_pkg) = qsearchs( 'cust_pkg', { 'pkgnum' => $1 } );
102   my %hash = $old_cust_pkg->hash;
103   $hash{'pkgpart'} = $pkgpart;
104   my($new_cust_pkg) = create FS::cust_pkg \%hash;
105   my $error = $new_cust_pkg->replace($old_cust_pkg);
106   eidiot "Error modifying cust_pkg record: $error\n" if $error;
107   print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new_cust_pkg->custnum);
108 }
109
110