diff options
Diffstat (limited to 'httemplate/edit/process')
-rw-r--r-- | httemplate/edit/process/cust_pkg_discount.html | 96 | ||||
-rw-r--r-- | httemplate/edit/process/elements/process.html | 2 | ||||
-rw-r--r-- | httemplate/edit/process/log_email.html | 18 | ||||
-rw-r--r-- | httemplate/edit/process/quick-cust_pkg.cgi | 29 | ||||
-rw-r--r-- | httemplate/edit/process/quotation_pkg_detail.html | 45 | ||||
-rw-r--r-- | httemplate/edit/process/rate_detail.html | 16 |
6 files changed, 165 insertions, 41 deletions
diff --git a/httemplate/edit/process/cust_pkg_discount.html b/httemplate/edit/process/cust_pkg_discount.html index 4a71f6975..143611ef9 100644 --- a/httemplate/edit/process/cust_pkg_discount.html +++ b/httemplate/edit/process/cust_pkg_discount.html @@ -14,9 +14,8 @@ <%init> my $curuser = $FS::CurrentUser::CurrentUser; - -die "access denied" - unless $curuser->access_right('Discount customer package'); +my $can_discount = $curuser->access_right('Discount customer package'); +my $can_waive_setup = $curuser->access_right('Waive setup fee'); #this search is really for security wrt agent virt... #maybe move it to the cust_pkg_discount->insert call? @@ -29,20 +28,81 @@ my $cust_pkg = qsearchs({ }); die 'unknown pkgnum' unless $cust_pkg; -my $cust_pkg_discount = new FS::cust_pkg_discount { - 'pkgnum' => $cust_pkg->pkgnum, - 'discountnum' => scalar($cgi->param('discountnum')), - 'months_used' => 0, - 'end_date' => '', #XXX - #for the create a new discount case - '_type' => scalar($cgi->param('discountnum__type')), - 'amount' => scalar($cgi->param('discountnum_amount')), - 'percent' => scalar($cgi->param('discountnum_percent')), - 'months' => scalar($cgi->param('discountnum_months')), - 'setup' => scalar($cgi->param('discountnum_setup')), - #'linked' => scalar($cgi->param('discountnum_linked')), - #'disabled' => $self->discountnum_disabled, -}; -my $error = $cust_pkg_discount->insert; +my $error; +my %discountnum = (setup => '', recur => ''); +if ( $cgi->param('setup_discountnum') == -2 ) { + + die "access denied" unless $can_waive_setup; # UI protects against this + # waive setup fee (not really a discount but treated as one in the UI) + if ( !$cust_pkg->get('setup') and !$cust_pkg->waive_setup ) { + $cust_pkg->set('waive_setup' => 'Y'); + $error = $cust_pkg->replace; + } + +} else { + if ( $cgi->param('setup_discountnum') =~ /^(-?\d+)$/ ) { + $discountnum{setup} = $1; + } + if ( $cust_pkg->waive_setup ) { + $cust_pkg->set('waive_setup', ''); + $error = $cust_pkg->replace; + } +} + +if ( $cgi->param('recur_discountnum') =~ /^(-?\d+)$/ ) { + + $discountnum{recur} = $1; + +} + +my @active_discounts = $cust_pkg->cust_pkg_discount_active; + +foreach my $setuprecur (qw(setup recur)) { + + if ( $cust_pkg->get('setup') and $setuprecur eq 'setup' ) { + # no point allowing setup discounts to be edited for a previously setup + # package + next; + } + + my ($active) = grep { $_->setuprecur eq $setuprecur } @active_discounts; + + if ( $active ) { + if ( $active->discount ne $discountnum{$setuprecur} ) { + $active->set('disabled' => 'Y'); + $error ||= $active->replace; + undef $active; + } else { + # it's the same discountnum; don't touch it + next; + } + } + + if ( $discountnum{$setuprecur} ) { + die "access_denied" unless $can_discount; + my $cust_pkg_discount = FS::cust_pkg_discount->new({ + 'pkgnum' => $cust_pkg->pkgnum, + 'discountnum' => $discountnum{$setuprecur}, + 'setuprecur' => $setuprecur, + 'months_used' => 0, + 'end_date' => '', #XXX + #for the create a new discount case + '_type' => scalar($cgi->param($setuprecur.'_discountnum__type')), + 'amount' => scalar($cgi->param($setuprecur.'_discountnum_amount')), + 'percent' => scalar($cgi->param($setuprecur.'_discountnum_percent')), + }); + if ( $setuprecur eq 'setup' ) { + $cust_pkg_discount->set('setup' => 'Y'); + $cust_pkg_discount->set('months' => 1); + } else { + if ( $cgi->param($setuprecur.'_discountnum_months') =~ /^(\w+)$/ ) { + $cust_pkg_discount->set('months' => $1); + } + } + + $error ||= $cust_pkg_discount->insert; + + } +} # foreach $setuprecur </%init> diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index a76f4befb..fd12c61d9 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -164,7 +164,9 @@ process(); % # some false laziness with the above % my ($form_name, $job_fields) = @{ $opt{'progress_init'} }; <form name="<% $form_name %>"> + <input type="hidden" name="<% $pkey %>" value="<% $new->get($pkey) %>"> % foreach my $field (@$job_fields) { +% next if $field eq $pkey; <input type="hidden" name="<% $field %>" value="<% $cgi->param($field) |h %>"> % } <& /elements/progress-init.html, diff --git a/httemplate/edit/process/log_email.html b/httemplate/edit/process/log_email.html new file mode 100644 index 000000000..769e180a8 --- /dev/null +++ b/httemplate/edit/process/log_email.html @@ -0,0 +1,18 @@ +<% include('elements/process.html', + 'table' => 'log_email', + %processopts + ) %> +<%init> + +my %opts = @_; + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right([ 'View system logs', 'Configuration' ]); + +my %processopts = $opts{'popup'} + ? ( 'popup_reload' => 'Logging email added' ) + : ( 'redirect' => $fsurl.'browse/log_email.html?' ); # id will be needlessly appended, should be harmless + +</%init> diff --git a/httemplate/edit/process/quick-cust_pkg.cgi b/httemplate/edit/process/quick-cust_pkg.cgi index f1d8c2696..60352154a 100644 --- a/httemplate/edit/process/quick-cust_pkg.cgi +++ b/httemplate/edit/process/quick-cust_pkg.cgi @@ -79,9 +79,6 @@ my $contactnum = $1; $cgi->param('locationnum') =~ /^(\-?\d*)$/ or die 'illegal locationnum '. $cgi->param('locationnum'); my $locationnum = $1; -$cgi->param('discountnum') =~ /^(\-?\d*)$/ - or die 'illegal discountnum '. $cgi->param('discountnum'); -my $discountnum = $1; # for going right to a provision service after ordering a package my( $svcpart, $part_svc ) = ( '', '' ); @@ -114,19 +111,29 @@ my %hash = ( 'refnum' => $refnum, 'contactnum' => $contactnum, 'locationnum' => $locationnum, - 'discountnum' => $discountnum, - #for the create a new discount case - 'discountnum__type' => scalar($cgi->param('discountnum__type')), - 'discountnum_amount' => scalar($cgi->param('discountnum_amount')), - 'discountnum_percent' => scalar($cgi->param('discountnum_percent')), - 'discountnum_months' => scalar($cgi->param('discountnum_months')), - 'discountnum_setup' => scalar($cgi->param('discountnum_setup')), 'contract_end' => ( scalar($cgi->param('contract_end')) ? parse_datetime($cgi->param('contract_end')) : '' ), - 'waive_setup' => ( $cgi->param('waive_setup') eq 'Y' ? 'Y' : '' ), ); + +if ( $cgi->param('setup_discountnum') =~ /^(-?\d+)$/ ) { + if ( $1 == -2 ) { + $hash{waive_setup} = 'Y'; + } else { + $hash{setup_discountnum} = $1; + $hash{setup_discountnum_amount} = $cgi->param('setup_discountnum_amount'); + $hash{setup_discountnum_percent} = $cgi->param('setup_discountnum_percent'); + } +} + +if ( $cgi->param('recur_discountnum') =~ /^(-?\d+)$/ ) { + $hash{recur_discountnum} = $1; + $hash{recur_discountnum_amount} = $cgi->param('recur_discountnum_amount'); + $hash{recur_discountnum_percent} = $cgi->param('recur_discountnum_percent'); + $hash{recur_discountnum_months} = $cgi->param('recur_discountnum_months'); +} + $hash{'custnum'} = $cust_main->custnum if $cust_main; if ( $cgi->param('start') eq 'on_hold' ) { diff --git a/httemplate/edit/process/quotation_pkg_detail.html b/httemplate/edit/process/quotation_pkg_detail.html new file mode 100644 index 000000000..2fc420280 --- /dev/null +++ b/httemplate/edit/process/quotation_pkg_detail.html @@ -0,0 +1,45 @@ +% if ( $error ) { +<% header('Error') %> +<FONT COLOR="#ff0000"><B><% $error |h %></B></FONT><BR><BR> +<CENTER><INPUT TYPE="BUTTON" VALUE="OK" onClick="parent.cClick()"></CENTER> +</BODY></HTML> +% } else { +<% header($action) %> + <SCRIPT TYPE="text/javascript"> + window.top.location.reload(); + </SCRIPT> + </BODY></HTML> +% } +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +die "access denied" + unless $curuser->access_right('Generate quotation'); + +$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'illegal pkgnum'; +my $pkgnum = $1; + +my $quotation_pkg = qsearchs({ + 'table' => 'quotation_pkg', + 'addl_from' => 'LEFT JOIN quotation USING ( quotationnum )'. + 'LEFT JOIN cust_main USING ( custnum )', + 'hashref' => { 'quotationpkgnum' => $pkgnum }, + 'extra_sql' => ' AND '. $curuser->agentnums_sql, +}); + +my @orig_details = $quotation_pkg->details(); + +my $action = 'Quotation details'. + ( scalar(@orig_details) ? ' changed ' : ' added ' ); + +my $param = $cgi->Vars; +my @details = (); +for ( my $row = 0; exists($param->{"detail$row"}); $row++ ) { + push @details, $param->{"detail$row"} + if $param->{"detail$row"} =~ /\S/; +} + +my $error = $quotation_pkg->set_details(@details); + +</%init> diff --git a/httemplate/edit/process/rate_detail.html b/httemplate/edit/process/rate_detail.html index f8a744418..4020ce9e2 100644 --- a/httemplate/edit/process/rate_detail.html +++ b/httemplate/edit/process/rate_detail.html @@ -2,7 +2,7 @@ 'table' => 'rate_detail', 'popup_reload' => 'Rate changed', #a popup "parent reload" for now #someday change the individual element and go away instead - 'noerror_callback' => $set_default_detail + #'noerror_callback' => $set_default_detail &> <%init> @@ -12,19 +12,11 @@ die "access denied" my $set_default_detail = sub { my ($cgi, $rate_detail) = @_; - if (!$rate_detail->dest_regionnum) { + if (!$rate_detail->dest_regionnum and !$rate_detail->cdrtypenum) { # then this is a global default rate + # default_detailnum is no longer used, but maintain it anyway (and point + # it at the one with null cdrtypenum) my $rate = $rate_detail->rate; - if ($rate->default_detailnum) { - if ($rate->default_detailnum == $rate_detail->ratedetailnum) { - return; - } else { - # there's somehow an existing default rate. remove it. - my $old_default = $rate->default_detail; - my $error = $old_default->delete; - die "$error (removing old default rate)\n" if $error; - } - } $rate->set('default_detailnum' => $rate_detail->ratedetailnum); my $error = $rate->replace; die "$error (setting default rate)\n" if $error; |