summaryrefslogtreecommitdiff
path: root/htdocs/edit/process/part_pkg.cgi
blob: 5c58752c8ca9026e8771bd7395d14dd4c2b9760c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl -Tw
#
# $Id: part_pkg.cgi,v 1.3 1998-11-21 07:17:58 ivan Exp $
#
# process/part_pkg.cgi: Edit package definitions (process form)
#
# ivan@sisd.com 97-dec-10
#
# don't update non-changing records in part_svc (causing harmless but annoying
# "Records identical" errors). ivan@sisd.com 98-feb-19
#
# Changes to allow page to work at a relative position in server
#       bmccane@maxbaud.net     98-apr-3
#
# Added `|| 0 ' when getting quantity off web page ivan@sisd.com 98-jun-4
#
# lose background, FS::CGI ivan@sisd.com 98-sep-2
#
# $Log: part_pkg.cgi,v $
# Revision 1.3  1998-11-21 07:17:58  ivan
# bugfix to work for regular aswell as custom pricing
#
# Revision 1.2  1998/11/15 13:16:15  ivan
# first pass as per-user custom pricing
#

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use FS::UID qw(cgisuidsetup);
use FS::CGI qw(eidiot popurl);
use FS::Record qw(qsearch qsearchs);
use FS::part_pkg qw(fields);
use FS::pkg_svc;
use FS::cust_pkg;

my($cgi)=new CGI;
&cgisuidsetup($cgi);

my($pkgpart)=$cgi->param('pkgpart');

my($old)=qsearchs('part_pkg',{'pkgpart'=>$pkgpart}) if $pkgpart;

my($new)=create FS::part_pkg ( {
  map {
    $_, $cgi->param($_);
  } fields('part_pkg')
} );

local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
local $SIG{QUIT} = 'IGNORE';
local $SIG{TERM} = 'IGNORE';
local $SIG{TSTP} = 'IGNORE';

if ( $pkgpart ) {
  my($error)=$new->replace($old);
  eidiot($error) if $error;
} else {
  my($error)=$new->insert;
  eidiot($error) if $error;
  $pkgpart=$new->getfield('pkgpart');
}

my($part_svc);
foreach $part_svc (qsearch('part_svc',{})) {
# don't update non-changing records in part_svc (causing harmless but annoying
# "Records identical" errors). ivan@sisd.com 98-jan-19
  #my($quantity)=$cgi->param('pkg_svc'. $part_svc->getfield('svcpart')),
  my($quantity)=$cgi->param('pkg_svc'. $part_svc->svcpart) || 0,
  my($old_pkg_svc)=qsearchs('pkg_svc',{
    'pkgpart'  => $pkgpart,
    'svcpart'  => $part_svc->getfield('svcpart'),
  });
  my($old_quantity)=$old_pkg_svc ? $old_pkg_svc->quantity : 0;
  next unless $old_quantity != $quantity; #!here
  my($new_pkg_svc)=create FS::pkg_svc({
    'pkgpart'  => $pkgpart,
    'svcpart'  => $part_svc->getfield('svcpart'),
    #'quantity' => $cgi->param('pkg_svc'. $part_svc->getfield('svcpart')),
    'quantity' => $quantity, 
  });
  if ($old_pkg_svc) {
    my($error)=$new_pkg_svc->replace($old_pkg_svc);
    eidiot($error) if $error;
  } else {
    my($error)=$new_pkg_svc->insert;
    eidiot($error) if $error;
  }
}

unless ( $cgi->param('pkgnum') && $cgi->param('pkgnum') =~ /^(\d+)$/ ) {
  #$req->cgi->redirect("../../view/part_pkg.cgi?$pkgpart");
  #$req->cgi->redirect("../../edit/part_pkg.cgi?$pkgpart");
  print $cgi->redirect(popurl(3). "/browse/part_pkg.cgi");
} else {
  my($old_cust_pkg) = qsearchs( 'cust_pkg', { 'pkgnum' => $1 } );
  my %hash = $old_cust_pkg->hash;
  $hash{'pkgpart'} = $pkgpart;
  my($new_cust_pkg) = create FS::cust_pkg \%hash;
  my $error = $new_cust_pkg->replace($old_cust_pkg);
  eidiot "Error modifying cust_pkg record: $error\n" if $error;
  print $cgi->redirect(popurl(3). "/view/cust_main.cgi?". $new_cust_pkg->custnum);
}