summaryrefslogtreecommitdiff
path: root/httemplate/edit/process
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/edit/process')
-rwxr-xr-xhttemplate/edit/process/REAL_cust_pkg.cgi57
-rw-r--r--httemplate/edit/process/bulk-part_pkg.html30
-rw-r--r--httemplate/edit/process/change-cust_pkg.html4
-rw-r--r--httemplate/edit/process/credit-cust_bill_pkg.html2
-rw-r--r--httemplate/edit/process/cust_location.cgi5
-rwxr-xr-xhttemplate/edit/process/cust_main.cgi38
-rw-r--r--httemplate/edit/process/cust_pkg_quantity.html33
-rw-r--r--httemplate/edit/process/cust_svc.cgi2
-rw-r--r--httemplate/edit/process/elements/process.html3
-rw-r--r--httemplate/edit/process/elements/svc_Common.html5
-rw-r--r--httemplate/edit/process/part_export.cgi1
-rwxr-xr-xhttemplate/edit/process/part_pkg.cgi17
-rw-r--r--httemplate/edit/process/part_pkg_usage.html67
-rw-r--r--httemplate/edit/process/quick-cust_pkg.cgi18
-rw-r--r--httemplate/edit/process/svc_phone.html17
15 files changed, 247 insertions, 52 deletions
diff --git a/httemplate/edit/process/REAL_cust_pkg.cgi b/httemplate/edit/process/REAL_cust_pkg.cgi
index 3e0ef59c1..fd2893487 100755
--- a/httemplate/edit/process/REAL_cust_pkg.cgi
+++ b/httemplate/edit/process/REAL_cust_pkg.cgi
@@ -19,36 +19,41 @@ die "access denied"
my $pkgnum = $cgi->param('pkgnum') or die;
my $old = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
my %hash = $old->hash;
-$hash{$_}= $cgi->param($_) ? parse_datetime($cgi->param($_)) : ''
- foreach qw( start_date setup bill last_bill contract_end );
+foreach ( qw( start_date setup bill last_bill contract_end ) ) {
+ if ( $cgi->param($_) =~ /^(\d+)$/ ) {
+ $hash{$_} = $1;
+ } else {
+ $hash{$_} = '';
+ }
# adjourn, expire, resume not editable this way
-
-my @errors = ();
-
-push @errors, '_bill_areyousure'
- if $hash{'bill'} != $old->bill # if the next bill date was changed
- && $hash{'bill'} < time # to a date in the past
- && ! $cgi->param('bill_areyousure'); # and it wasn't confirmed
-
-push @errors, '_setup_areyousure'
- if ! $hash{'setup'} && $old->setup # if the setup date was removed
- && ! $cgi->param('setup_areyousure'); # and it wasn't confirmed
-
-push @errors, '_setupadd_areyousure'
- if $hash{'setup'} && ! $old->setup # if the setup date was added
- && ! $cgi->param('setupadd_areyousure'); # and it wasn't confirmed
-
-push @errors, '_start'
- if $hash{'start_date'} && !$old->start_date # if a start date was added
- && $hash{'setup'}; # but there's a setup date
+}
my $new;
my $error;
-if ( @errors ) {
- $error = join(',', @errors);
-} else {
- $new = new FS::cust_pkg \%hash;
- $error = $new->replace($old);
+$new = new FS::cust_pkg \%hash;
+$error = $new->replace($old);
+
+if (!$error) {
+ my @supp_pkgs = $old->supplemental_pkgs;
+ foreach $new (@supp_pkgs) {
+ foreach ( qw( start_date setup contract_end ) ) {
+ # propagate these to supplementals
+ $new->set($_, $hash{$_});
+ }
+ if ( $hash{'bill'} ne $old->get('bill') ) {
+ if ( $hash{'bill'} and $old->get('bill') ) {
+ # adjust by the same interval
+ my $diff = $hash{'bill'} - $old->get('bill');
+ $new->set('bill', $new->get('bill') + $diff);
+ } else {
+ # absolute date
+ $new->set('bill', $hash{'bill'});
+ }
+ }
+ $error = $new->replace;
+ $error .= ' (supplemental package '.$new->pkgnum.')' if $error;
+ last if $error;
+ }
}
</%init>
diff --git a/httemplate/edit/process/bulk-part_pkg.html b/httemplate/edit/process/bulk-part_pkg.html
new file mode 100644
index 000000000..4775a9334
--- /dev/null
+++ b/httemplate/edit/process/bulk-part_pkg.html
@@ -0,0 +1,30 @@
+% if ( $error ) {
+% $cgi->param('error', $error);
+<% $cgi->redirect(popurl(3).'/edit/bulk-part_pkg.cgi?', $cgi->query_string) %>
+% } else {
+<% $cgi->redirect(popurl(3).'/browse/part_pkg.cgi') %>
+% }
+<%init>
+die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Bulk edit package definitions');
+
+my @pkgparts = $cgi->param('pkgpart')
+ or die "no package definitions selected";
+
+my %changes;
+foreach my $param (grep { /^report_option_\d+$/ } $cgi->param) {
+ if ( length($cgi->param($param)) ) {
+ if ( $cgi->param($param) == 1 ) {
+ $changes{$param} = 1;
+ } else {
+ $changes{$param} = '';
+ }
+ }
+}
+
+my $error;
+foreach my $pkgpart (@pkgparts) {
+ my $part_pkg = FS::part_pkg->by_key($pkgpart);
+ my %options = ( $part_pkg->options, %changes );
+ $error ||= $part_pkg->replace( options => \%options );
+}
+</%init>
diff --git a/httemplate/edit/process/change-cust_pkg.html b/httemplate/edit/process/change-cust_pkg.html
index 2770f3283..77f261d56 100644
--- a/httemplate/edit/process/change-cust_pkg.html
+++ b/httemplate/edit/process/change-cust_pkg.html
@@ -32,11 +32,11 @@ my %change = map { $_ => scalar($cgi->param($_)) }
$change{'keep_dates'} = 1;
if ( $cgi->param('locationnum') == -1 ) {
- my $cust_location = new FS::cust_location {
+ my $cust_location = FS::cust_location->new_or_existing({
'custnum' => $cust_pkg->custnum,
map { $_ => scalar($cgi->param($_)) }
qw( address1 address2 city county state zip country )
- };
+ });
$change{'cust_location'} = $cust_location;
}
diff --git a/httemplate/edit/process/credit-cust_bill_pkg.html b/httemplate/edit/process/credit-cust_bill_pkg.html
index cbcf619ca..8e66368d4 100644
--- a/httemplate/edit/process/credit-cust_bill_pkg.html
+++ b/httemplate/edit/process/credit-cust_bill_pkg.html
@@ -10,7 +10,7 @@
<%init>
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Post credit');
+ unless $FS::CurrentUser::CurrentUser->access_right('Credit line items');
my @billpkgnum_setuprecurs =
map { $_ =~ /^billpkgnum(\d+\-\w*)$/ or die 'gm#23'; $1; }
diff --git a/httemplate/edit/process/cust_location.cgi b/httemplate/edit/process/cust_location.cgi
index b9f93db8b..56c3968f6 100644
--- a/httemplate/edit/process/cust_location.cgi
+++ b/httemplate/edit/process/cust_location.cgi
@@ -28,11 +28,10 @@ my $cust_location = qsearchs({
});
die "unknown locationnum $locationnum" unless $cust_location;
-my $new = FS::cust_location->new({
+my $new = FS::cust_location->new_or_existing({
custnum => $cust_location->custnum,
prospectnum => $cust_location->prospectnum,
- map { $_ => scalar($cgi->param($_)) }
- qw( address1 address2 city county state zip country )
+ map { $_ => scalar($cgi->param($_)) } FS::cust_main->location_fields
});
my $error = $cust_location->move_to($new);
diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi
index 31ec4ab12..c1f815550 100755
--- a/httemplate/edit/process/cust_main.cgi
+++ b/httemplate/edit/process/cust_main.cgi
@@ -16,8 +16,8 @@ my $DEBUG = 0;
</%once>
<%init>
-die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
+my $curuser = $FS::CurrentUser::CurrentUser;
+die "access denied" unless $curuser->access_right('Edit customer');
my $conf = new FS::Conf;
@@ -62,6 +62,18 @@ $cgi->param('invoicing_list', join(',', @invoicing_list) );
$cgi->param('duplicate_of_custnum') =~ /^(\d+)$/;
my $duplicate_of = $1;
+# if this is enabled, enforce it
+if ( $conf->exists('agent-ship_address', $cgi->param('agentnum')) ) {
+ my $agent = FS::agent->by_key($cgi->param('agentnum'));
+ my $agent_cust_main = $agent->agent_cust_main;
+ if ( $agent_cust_main ) {
+ my $agent_location = $agent_cust_main->ship_location;
+ foreach (qw(address1 city state zip country latitude longitude district)) {
+ $cgi->param("ship_$_", $agent_location->get($_));
+ }
+ }
+}
+
my %locations;
for my $pre (qw(bill ship)) {
@@ -71,10 +83,7 @@ for my $pre (qw(bill ship)) {
}
$hash{'custnum'} = $cgi->param('custnum');
warn Dumper \%hash if $DEBUG;
- # if we can qsearchs it, then it's unchanged, so use that
- $locations{$pre} = qsearchs('cust_location', \%hash)
- || FS::cust_location->new( \%hash );
-
+ $locations{$pre} = FS::cust_location->new_or_existing(\%hash);
}
if ( ($cgi->param('same') || '') eq 'Y' ) {
@@ -156,9 +165,14 @@ foreach my $dfield (qw(
$new->setfield('paid', $cgi->param('paid') )
if $cgi->param('paid');
-my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
-my @tax_exempt = grep { $cgi->param("tax_$_") eq 'Y' } @exempt_groups;
-my %tax_exempt = map { $_ => scalar($cgi->param("tax_$_".'_num')) } @tax_exempt;
+my %options = ();
+if ( $curuser->access_right('Edit customer tax exemptions') ) {
+ my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
+ my @tax_exempt = grep { $cgi->param("tax_$_") eq 'Y' } @exempt_groups;
+ $options{'tax_exemption'} = {
+ map { $_ => scalar($cgi->param("tax_$_".'_num')) } @tax_exempt
+ };
+}
#perhaps this stuff should go to cust_main.pm
if ( $new->custnum eq '' or $duplicate_of ) {
@@ -266,8 +280,8 @@ if ( $new->custnum eq '' or $duplicate_of ) {
else {
# create the customer
$error ||= $new->insert( \%hash, \@invoicing_list,
- 'tax_exemption'=> \%tax_exempt,
- 'prospectnum' => scalar($cgi->param('prospectnum')),
+ %options,
+ prospectnum => scalar($cgi->param('prospectnum')),
);
my $conf = new FS::Conf;
@@ -328,7 +342,7 @@ if ( $new->custnum eq '' or $duplicate_of ) {
warn Dumper({ new => $new, old => $old }) if $DEBUG;
$error ||= $new->replace( $old, \@invoicing_list,
- 'tax_exemption' => \%tax_exempt,
+ %options,
);
warn "$me returned from replace" if $DEBUG;
diff --git a/httemplate/edit/process/cust_pkg_quantity.html b/httemplate/edit/process/cust_pkg_quantity.html
new file mode 100644
index 000000000..fb2657252
--- /dev/null
+++ b/httemplate/edit/process/cust_pkg_quantity.html
@@ -0,0 +1,33 @@
+% if ($error) {
+% $cgi->param('error', $error);
+% $cgi->redirect(popurl(3). 'edit/cust_pkg_quantity.html?'. $cgi->query_string );
+% } else {
+
+ <& /elements/header-popup.html, "Quantity 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({
+ '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;
+
+$cgi->param('quantity') =~ /^(\d+)$/;
+my $quantity = $1;
+my $error = $cust_pkg->set_quantity($1);
+
+</%init>
diff --git a/httemplate/edit/process/cust_svc.cgi b/httemplate/edit/process/cust_svc.cgi
index e22cbb201..7cb1d6d8f 100644
--- a/httemplate/edit/process/cust_svc.cgi
+++ b/httemplate/edit/process/cust_svc.cgi
@@ -6,7 +6,7 @@
%}
<%init>
-die 'access deined'
+die 'access denied'
unless $FS::CurrentUser::CurrentUser->access_right('Change customer service');
my $svcnum = $cgi->param('svcnum');
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index 2d39e9dce..fb1ee7a27 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -263,6 +263,9 @@ foreach my $value ( @values ) {
if ( !$error ) {
if ( $old_pkey ) {
+
+ &{ $opt{'edit_callback'} }( $new, $old ) if $opt{'edit_callback'};
+
$error = $new->replace($old, @args);
} else {
$error = $new->insert(@args);
diff --git a/httemplate/edit/process/elements/svc_Common.html b/httemplate/edit/process/elements/svc_Common.html
index 5a8afbd6c..06f4c00b1 100644
--- a/httemplate/edit/process/elements/svc_Common.html
+++ b/httemplate/edit/process/elements/svc_Common.html
@@ -10,5 +10,10 @@ my %opt = @_;
my $table = $opt{'table'};
$opt{'fields'} ||= [ fields($table) ];
push @{ $opt{'fields'} }, qw( pkgnum svcpart );
+foreach (fields($table)) {
+ if ( $cgi->param($_.'_classnum') ) {
+ push @{ $opt{'fields'} }, $_.'_classnum';
+ }
+}
</%init>
diff --git a/httemplate/edit/process/part_export.cgi b/httemplate/edit/process/part_export.cgi
index bcb9c0df1..e0c470675 100644
--- a/httemplate/edit/process/part_export.cgi
+++ b/httemplate/edit/process/part_export.cgi
@@ -56,6 +56,7 @@ my $new = new FS::part_export ( {
if ( $cgi->param('svc_machine') eq 'Y' ) {
$new->machine('_SVC_MACHINE');
$new->part_export_machine_textarea( $cgi->param('part_export_machine') );
+ $new->default_machine_name( $cgi->param('default_machine_name') );
}
my $error;
diff --git a/httemplate/edit/process/part_pkg.cgi b/httemplate/edit/process/part_pkg.cgi
index c388676df..932e33b1d 100755
--- a/httemplate/edit/process/part_pkg.cgi
+++ b/httemplate/edit/process/part_pkg.cgi
@@ -10,6 +10,7 @@
'precheck_callback' => $precheck_callback,
'args_callback' => $args_callback,
'process_m2m' => \@process_m2m,
+ 'process_o2m' => \@process_o2m,
)
%>
<%init>
@@ -185,6 +186,15 @@ my @process_m2m = (
grep /^svc_dst_pkgpart/, $cgi->param
],
},
+ { 'link_table' => 'part_pkg_link',
+ 'target_table' => 'part_pkg',
+ 'base_field' => 'src_pkgpart',
+ 'target_field' => 'dst_pkgpart',
+ 'hashref' => { 'link_type' => 'supp', 'hidden' => '' },
+ 'params' => [ map $cgi->param($_),
+ grep /^supp_dst_pkgpart/, $cgi->param
+ ],
+ },
map {
my $hidden = $_;
{ 'link_table' => 'part_pkg_link',
@@ -235,4 +245,11 @@ if ( $cgi->param('pkgpart') || ! $conf->exists('agent_defaultpkg') ) {
};
}
+my @process_o2m = (
+ {
+ 'table' => 'part_pkg_msgcat',
+ 'fields' => [qw( locale pkg )],
+ },
+);
+
</%init>
diff --git a/httemplate/edit/process/part_pkg_usage.html b/httemplate/edit/process/part_pkg_usage.html
new file mode 100644
index 000000000..eb6c37b82
--- /dev/null
+++ b/httemplate/edit/process/part_pkg_usage.html
@@ -0,0 +1,67 @@
+% if ( $is_error ) {
+% $cgi->param('error' => \%part_pkg_usage);
+% # internal redirect, because it's a lot of state to pass through
+<& /browse/part_pkg_usage.html &>
+% } else {
+% # uh, not quite sure...
+<% $cgi->redirect($fsurl.'browse/part_pkg.cgi') %>
+% }
+<%init>
+my %vars = $cgi->Vars;
+my %part_pkg_usage;
+my $is_error;
+foreach my $pkgpart ($cgi->param('pkgpart')) {
+ next unless $pkgpart =~ /^\d+$/;
+ my $part_pkg = FS::part_pkg->by_key($pkgpart)
+ or die "unknown pkgpart $pkgpart";
+ my %old = map { $_->pkgusagepart => $_ } $part_pkg->part_pkg_usage;
+ $part_pkg_usage{$pkgpart} ||= [];
+ my @rows;
+ foreach (grep /^pkgpart$pkgpart/, keys %vars) {
+ /^pkgpart\d+_(\w+\D)(\d+)$/ or die "misspelled field name '$_'";
+ my $value = delete $vars{$_};
+ my $field = $1;
+ my $row = $2;
+ $rows[$row] ||= {};
+ $rows[$row]->{$field} = $value;
+ }
+
+ foreach my $row (@rows) {
+ next if !defined($row);
+ my $error;
+ my %classes;
+ foreach my $class (grep /^class/, keys %$row) {
+ $class =~ /^class(\d+)_$/;
+ my $classnum = $1;
+ $classes{$classnum} = delete $row->{$class};
+ }
+ my $usage = FS::part_pkg_usage->new($row);
+ $usage->set('pkgpart', $pkgpart);
+ if ( $usage->pkgusagepart and $row->{minutes} > 0 ) {
+ $error = $usage->replace(\%classes);
+ # and don't delete the existing one
+ delete($old{$usage->pkgusagepart});
+ } elsif ( $row->{minutes} > 0 ) {
+ $error = $usage->insert(\%classes);
+ } else {
+ next;
+ }
+ if ( $error ) {
+ $usage->set('error', $error);
+ $is_error = 1;
+ }
+ push @{ $part_pkg_usage{$pkgpart} }, $usage;
+ }
+
+ foreach my $usage (values %old) {
+ # all of these were not sent back by the client, so delete them
+ my $error = $usage->delete;
+ if ( $error ) {
+ $usage->set('error', $error);
+ $is_error = 1;
+ unshift @{ $part_pkg_usage{$pkgpart} }, $usage;
+ }
+ }
+
+}
+</%init>
diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi
index 2dadbccdc..0cc17d36b 100644
--- a/httemplate/edit/process/quick-cust_pkg.cgi
+++ b/httemplate/edit/process/quick-cust_pkg.cgi
@@ -70,6 +70,9 @@ my $quantity = $1 || 1;
$cgi->param('refnum') =~ /^(\d*)$/
or die 'illegal refnum '. $cgi->param('refnum');
my $refnum = $1;
+$cgi->param('contactnum') =~ /^(\-?\d*)$/
+ or die 'illegal contactnum '. $cgi->param('contactnum');
+my $contactnum = $1;
$cgi->param('locationnum') =~ /^(\-?\d*)$/
or die 'illegal locationnum '. $cgi->param('locationnum');
my $locationnum = $1;
@@ -109,6 +112,7 @@ my %hash = (
: ''
),
'refnum' => $refnum,
+ 'contactnum' => $contactnum,
'locationnum' => $locationnum,
'discountnum' => $discountnum,
#for the create a new discount case
@@ -142,11 +146,19 @@ if ( $quotationnum ) {
my %opt = ( 'cust_pkg' => $cust_pkg );
+ if ( $contactnum == -1 ) {
+ my $contact = FS::contact->new({
+ 'custnum' => scalar($cgi->param('custnum')),
+ map { $_ => scalar($cgi->param("contactnum_$_")) } qw( first last )
+ });
+ $opt{'contact'} = $contact;
+ }
+
if ( $locationnum == -1 ) {
- my $cust_location = new FS::cust_location {
+ my $cust_location = FS::cust_location->new_or_existing({
map { $_ => scalar($cgi->param($_)) }
- qw( custnum address1 address2 city county state zip country geocode )
- };
+ ('custnum', FS::cust_main->location_fields)
+ });
$opt{'cust_location'} = $cust_location;
}
diff --git a/httemplate/edit/process/svc_phone.html b/httemplate/edit/process/svc_phone.html
index 7a3b43d32..9983ea2cb 100644
--- a/httemplate/edit/process/svc_phone.html
+++ b/httemplate/edit/process/svc_phone.html
@@ -2,6 +2,7 @@
'table' => 'svc_phone',
'args_callback' => $args_callback,
'value_callback' => $value_callback,
+ 'edit_callback' => $edit_callback,
%opt,
&>
<%init>
@@ -28,6 +29,9 @@ my $right = $opt{'bulk'} ? 'Bulk provision customer service'
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right($right);
+$cgi->param('phonenum', $cgi->param('phonenum_manual') )
+ if $cgi->param('phonenum_which') eq 'phonenum_manual';
+
my $tollfreephonenum = $cgi->param('tollfreephonenum');
$cgi->param('phonenum',$tollfreephonenum) if $tollfreephonenum =~ /^\d+$/;
@@ -36,10 +40,10 @@ my $args_callback = sub {
my %opt = ();
if ( $cgi->param('locationnum') == -1 ) {
- my $cust_location = new FS::cust_location {
+ my $cust_location = FS::cust_location->new_or_existing({
map { $_ => scalar($cgi->param($_)) }
qw( custnum address1 address2 city county state zip country )
- };
+ });
$opt{'cust_location'} = $cust_location;
}
@@ -48,8 +52,13 @@ my $args_callback = sub {
};
my $value_callback = sub {
- my ($field, $value) = @_;
- ($field =~ /_date$/) ? parse_datetime($value) : $value;
+ my ($field, $value) = @_;
+ ($field =~ /_date$/) ? parse_datetime($value) : $value;
+};
+
+my $edit_callback = sub {
+ my( $new, $old ) = @_;
+ $new->sip_password( $old->sip_password ) if $new->sip_password eq '*HIDDEN*';
};
</%init>