summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/edit/process/change-cust_pkg.html46
-rwxr-xr-xhttemplate/edit/process/cust_pkg.cgi64
-rw-r--r--httemplate/elements/location.html6
-rw-r--r--httemplate/elements/tr-select-cust_location.html4
-rwxr-xr-xhttemplate/misc/change_pkg.cgi66
-rw-r--r--httemplate/view/cust_main/packages/location.html23
-rw-r--r--httemplate/view/cust_main/packages/package.html12
7 files changed, 130 insertions, 91 deletions
diff --git a/httemplate/edit/process/change-cust_pkg.html b/httemplate/edit/process/change-cust_pkg.html
new file mode 100644
index 000000000..7356e6122
--- /dev/null
+++ b/httemplate/edit/process/change-cust_pkg.html
@@ -0,0 +1,46 @@
+% if ($error) {
+% $cgi->param('error', $error);
+% $cgi->redirect(popurl(3). 'misc/change_pkg.cgi?'. $cgi->query_string );
+% } else {
+
+ <% header("Package changed") %>
+ <SCRIPT TYPE="text/javascript">
+ window.top.location.reload();
+ </SCRIPT>
+ </BODY>
+ </HTML>
+
+% }
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Change customer package');
+
+my $cust_pkg = qsearchs({
+ #'select' => 'cust_pkg.*',
+ 'table' => 'cust_pkg',
+ 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
+ 'hashref' => { 'pkgnum' => scalar($cgi->param('pkgnum')), },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+});
+die 'unknown pkgnum' unless $cust_pkg;
+
+my %change = map { $_ => scalar($cgi->param($_)) }
+ qw( locationnum pkgpart );
+
+if ( $cgi->param('locationnum') == -1 ) {
+ my $cust_location = new FS::cust_location {
+ 'custnum' => $cust_pkg->custnum,
+ map { $_ => scalar($cgi->param($_)) }
+ qw( address1 address2 city county state zip country )
+ };
+ $change{'cust_location'} = $cust_location;
+}
+
+my $pkg_or_error = $cust_pkg->change( \%change );
+
+my $error = ref($pkg_or_error) ? '' : $pkg_or_error;
+
+</%init>
diff --git a/httemplate/edit/process/cust_pkg.cgi b/httemplate/edit/process/cust_pkg.cgi
index 272ddcc47..94c084eae 100755
--- a/httemplate/edit/process/cust_pkg.cgi
+++ b/httemplate/edit/process/cust_pkg.cgi
@@ -1,22 +1,15 @@
% if ($error) {
% $cgi->param('error', $error);
-% $cgi->redirect(popurl(3). $error_redirect. '?'. $cgi->query_string );
-% } elsif ( $action eq 'change' ) {
-
- <% header("Package changed") %>
- <SCRIPT TYPE="text/javascript">
- window.top.location.reload();
- </SCRIPT>
- </BODY>
- </HTML>
-
-% } elsif ( $action eq 'bulk' ) {
-<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
+% $cgi->redirect(popurl(3). 'edit/cust_pkg.cgi?'. $cgi->query_string );
% } else {
-% die "guru exception #5: action is neither change nor bulk!";
-% }
+<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %>
<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+ unless $curuser->access_right('Bulk change customer packages');
+
my $error = '';
#untaint custnum
@@ -28,46 +21,19 @@ my @remove_pkgnums = map {
$1;
} $cgi->param('remove_pkg');
-my $curuser = $FS::CurrentUser::CurrentUser;
-
my( $action, $error_redirect ) = ( '', '' );
my @pkgparts = ();
-if ( $cgi->param('action') eq 'change' ) { #came from misc/change_pkg.cgi
-
- $action = 'change';
- $error_redirect = "misc/change_pkg.cgi";
- die "access denied"
- unless $curuser->access_right('Change customer package');
-
- if ( $cgi->param('new_pkgpart') =~ /^(\d+)$/ ) {
- @pkgparts = ($1);
- } else {
- $error = 'Select a new package';
- }
-
-} elsif ( $cgi->param('action') eq 'bulk' ) { #came from edit/cust_pkg.cgi
-
- $action = 'bulk';
- $error_redirect = "edit/cust_pkg.cgi";
-
- die "access denied"
- unless $curuser->access_right('Bulk change customer packages');
-
- foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
- if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
- my $num_pkgs = $1;
- while ( $num_pkgs-- ) {
- push @pkgparts,$pkgpart;
- }
- } else {
- $error = "Illegal quantity";
- last;
+foreach my $pkgpart ( map /^pkg(\d+)$/ ? $1 : (), $cgi->param ) {
+ if ( $cgi->param("pkg$pkgpart") =~ /^(\d+)$/ ) {
+ my $num_pkgs = $1;
+ while ( $num_pkgs-- ) {
+ push @pkgparts,$pkgpart;
}
+ } else {
+ $error = "Illegal quantity";
+ last;
}
-
-} else {
- die "guru exception #5: action is neither change nor bulk!";
}
$error ||= FS::cust_pkg::order($custnum,\@pkgparts,\@remove_pkgnums);
diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html
index f21b8ad01..b0b30d3b1 100644
--- a/httemplate/elements/location.html
+++ b/httemplate/elements/location.html
@@ -22,7 +22,7 @@ Example:
NAME = "<%$pre%>address1"
ID = "<%$pre%>address1"
VALUE = "<% $object->get($pre.'address1') |h %>"
- SIZE = 70
+ SIZE = 58
onChange = "<% $onchange %>"
<% $disabled %>
<% $style %>
@@ -37,7 +37,7 @@ Example:
NAME = "<%$pre%>address2"
ID = "<%$pre%>address2"
VALUE = "<% $object->get($pre.'address2') |h %>"
- SIZE = 70
+ SIZE = 58
onChange = "<% $onchange %>"
<% $disabled %>
<% $style %>
@@ -56,7 +56,7 @@ Example:
<% $disabled %>
<% $style %>
>
- </TD>
+ </TD>
<TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
<TD>
<% include('/elements/select-county.html', %select_hash ) %>
diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html
index b62c65c03..5b023f165 100644
--- a/httemplate/elements/tr-select-cust_location.html
+++ b/httemplate/elements/tr-select-cust_location.html
@@ -118,7 +118,7 @@ Example:
</SCRIPT>
<TR>
- <TH ALIGN="right">Service location</TH>
+ <TH ALIGN="right">Service&nbsp;location</TH>
<TD COLSPAN=7>
<SELECT NAME="locationnum" onChange="locationnum_changed(this);">
<OPTION VALUE="">(default service address)
@@ -166,7 +166,7 @@ if ( $locationnum && $locationnum != -1 ) {
or die "unknown locationnum";
} else {
$cust_location = new FS::cust_location;
- if ( $cgi->param('error') && $locationnum == -1 ) {
+ if ( $locationnum == -1 ) {
$cust_location->$_( $cgi->param($_) ) foreach @location_fields;
} else {
$cust_location->$_( $cust_main->$_() ) foreach @location_fields;
diff --git a/httemplate/misc/change_pkg.cgi b/httemplate/misc/change_pkg.cgi
index d6a24fb32..c4dfca200 100755
--- a/httemplate/misc/change_pkg.cgi
+++ b/httemplate/misc/change_pkg.cgi
@@ -2,35 +2,37 @@
<% include('/elements/error.html') %>
-<FORM ACTION="<% $p %>edit/process/cust_pkg.cgi" METHOD=POST>
-<INPUT TYPE="hidden" NAME="action" VALUE="change">
-<INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
-<INPUT TYPE="hidden" NAME="remove_pkg" VALUE="<% $pkgnum %>">
+<FORM ACTION="<% $p %>edit/process/change-cust_pkg.html" METHOD=POST>
+<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
<% ntable('#cccccc') %>
<TR>
- <TD>Current package:&nbsp;</TD>
- <TD>
- <B><% $part_pkg->pkgpart %>: <% $part_pkg->pkg %> - <% $part_pkg->comment %></B>
+ <TH ALIGN="right">Current package</TH>
+ <TD COLSPAN=7>
+ <% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B> - <% $part_pkg->comment |h %>
</TD>
</TR>
<TR>
- <TD>New package: </TD>
- <TD><% include('/elements/select-cust-part_pkg.html',
- 'cust_main' => $cust_main,
- 'element_name' => 'new_pkgpart',
- 'extra_sql' => ' AND pkgpart != '. $cust_pkg->pkgpart,
- 'curr_value' => ( $cgi->param('error')
- ? scalar($cgi->param('new_pkgpart'))
- : ''
- ),
- )
- %>
+ <TH ALIGN="right">New package</TH>
+ <TD COLSPAN=7>
+ <% include('/elements/select-cust-part_pkg.html',
+ 'cust_main' => $cust_main,
+ 'element_name' => 'pkgpart',
+ #'extra_sql' => ' AND pkgpart != '. $cust_pkg->pkgpart,
+ 'curr_value' => scalar($cgi->param('pkgpart')),
+ )
+ %>
</TD>
</TR>
+ <% include('/elements/tr-select-cust_location.html',
+ 'cgi' => $cgi,
+ 'cust_main' => $cust_main,
+ )
+ %>
+
</TABLE>
<BR>
@@ -42,28 +44,28 @@
<%init>
+my $conf = new FS::Conf;
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Change customer package');
-
-my $pkgnum;
-if ( $cgi->param('error') ) {
- $pkgnum = ($cgi->param('remove_pkg'))[0];
-} else {
- $pkgnum = $cgi->param('pkgnum');
-}
+ unless $curuser->access_right('Change customer package');
+
+my $pkgnum = scalar($cgi->param('pkgnum'));
$pkgnum =~ /^(\d+)$/ or die "illegal pkgnum $pkgnum";
$pkgnum = $1;
-my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $pkgnum } )
- or die "unknown pkgnum $pkgnum";
-my $custnum = $cust_pkg->custnum;
-
-my $conf = new FS::Conf;
+my $cust_pkg =
+ qsearchs({
+ 'table' => 'cust_pkg',
+ 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
+ 'hashref' => { 'pkgnum' => $pkgnum },
+ 'extra_sql' => ' AND '. $curuser->agentnums_sql,
+ }) or die "unknown pkgnum $pkgnum";
my $cust_main = $cust_pkg->cust_main
or die "can't get cust_main record for custnum ". $cust_pkg->custnum.
" ( pkgnum ". cust_pkg->pkgnum. ")";
-my $agent = $cust_main->agent;
my $part_pkg = $cust_pkg->part_pkg;
diff --git a/httemplate/view/cust_main/packages/location.html b/httemplate/view/cust_main/packages/location.html
index 0f58b36fc..3c641304a 100644
--- a/httemplate/view/cust_main/packages/location.html
+++ b/httemplate/view/cust_main/packages/location.html
@@ -19,17 +19,40 @@
</I>
+% if ($FS::CurrentUser::CurrentUser->access_right('Change customer package')) {
+ <FONT SIZE=-1>
+ (&nbsp;<%pkg_change_location_link($cust_pkg)%>&nbsp;)
+ </FONT>
+% }
+
</TD>
<%init>
my %opt = @_;
+my $conf = new FS::Conf;
+
my $bgcolor = $opt{'bgcolor'};
my $cust_pkg = $opt{'cust_pkg'};
my $part_pkg = $opt{'part_pkg'};
my $conf = new FS::Conf;
my $countrydefault = $conf->config('countrydefault') || 'US';
+my $statedefault = $conf->config('statedefault')
+ || ($countrydefault eq 'US' ? 'CA' : '');
my $loc = $cust_pkg->cust_location_or_main;
+sub pkg_change_location_link {
+ my $cust_pkg = shift;
+ my $pkgpart = $cust_pkg->pkgpart;
+ include( '/elements/popup_link-cust_pkg.html',
+ 'action' => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
+ "address1=;address2=;city=;county=;state=$statedefault;".
+ "zip=;country=$countrydefault",
+ 'label' => 'Change&nbsp;location',
+ 'actionlabel' => 'Change',
+ 'cust_pkg' => $cust_pkg,
+ );
+}
+
</%init>
diff --git a/httemplate/view/cust_main/packages/package.html b/httemplate/view/cust_main/packages/package.html
index 4311d8cf2..b07e1af94 100644
--- a/httemplate/view/cust_main/packages/package.html
+++ b/httemplate/view/cust_main/packages/package.html
@@ -184,12 +184,14 @@ sub pkg_link {
}
sub pkg_change_link {
+ my $cust_pkg = shift;
+ my $locationnum = $cust_pkg->locationnum;
include( '/elements/popup_link-cust_pkg.html',
- 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
- 'label' => 'Change&nbsp;package',
- 'actionlabel' => 'Change',
- 'cust_pkg' => shift,
- )
+ 'action' => $p. "misc/change_pkg.cgi?locationnum=$locationnum",
+ 'label' => 'Change&nbsp;package',
+ 'actionlabel' => 'Change',
+ 'cust_pkg' => $cust_pkg,
+ );
}
sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates', @_ ); }