diff options
Diffstat (limited to 'httemplate')
| -rw-r--r-- | httemplate/browse/commission_schedule.html | 70 | ||||
| -rw-r--r-- | httemplate/edit/commission_schedule.html | 53 | ||||
| -rw-r--r-- | httemplate/edit/process/commission_schedule.html | 36 | ||||
| -rw-r--r-- | httemplate/elements/commission_rate.html | 68 | ||||
| -rw-r--r-- | httemplate/elements/menu.html | 5 | ||||
| -rwxr-xr-x | httemplate/elements/tr-select-reason.html | 3 |
6 files changed, 232 insertions, 3 deletions
diff --git a/httemplate/browse/commission_schedule.html b/httemplate/browse/commission_schedule.html new file mode 100644 index 000000000..5a4f9840e --- /dev/null +++ b/httemplate/browse/commission_schedule.html @@ -0,0 +1,70 @@ +<& elements/browse.html, + 'title' => "Commission schedules", + 'name' => "commission schedules", + 'menubar' => [ 'Add a new schedule' => + $p.'edit/commission_schedule.html' + ], + 'query' => { 'table' => 'commission_schedule', }, + 'count_query' => 'SELECT COUNT(*) FROM commission_schedule', + 'header' => [ '#', + 'Name', + 'Rates', + ], + 'fields' => [ 'schedulenum', + 'schedulename', + $rates_sub, + ], + 'links' => [ $link, + $link, + '', + ], + 'disable_total' => 1, +&> +<%init> + +my $money_char = FS::Conf->new->config('money_char') || '$'; + +my $ordinal_sub = sub { + # correct from 1 to 12... + my $num = shift; + $num == 1 ? '1st' : + $num == 2 ? '2nd' : + $num == 3 ? '3rd' : + $num . 'th' +}; + +my $rates_sub = sub { + my $schedule = shift; + my @rates = sort { $a->cycle <=> $b->cycle } $schedule->commission_rate; + my @data; + my $basis = emt(lc( $FS::commission_schedule::basis_options{$schedule->basis} )); + foreach my $rate (@rates) { + my $desc = ''; + if ( $rate->amount > 0 ) { + $desc = $money_char . sprintf('%.2f', $rate->amount); + } + if ( $rate->percent > 0 ) { + $desc .= ' + ' if $desc; + $desc .= $rate->percent . '% ' . emt('of') . ' ' . $basis; + } + next if !$desc; + $desc = &$ordinal_sub($rate->cycle) . ' ' . emt('invoice') . + ': ' . $desc; + + push @data, + [ + { + 'data' => $desc, + 'align' => 'right', + } + ]; + } + \@data; +}; + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $link = [ $p.'edit/commission_schedule.html?', 'schedulenum' ]; + +</%init> diff --git a/httemplate/edit/commission_schedule.html b/httemplate/edit/commission_schedule.html new file mode 100644 index 000000000..c76a3618e --- /dev/null +++ b/httemplate/edit/commission_schedule.html @@ -0,0 +1,53 @@ +<& elements/edit.html, + name_singular => 'schedule', + table => 'commission_schedule', + viewall_dir => 'browse', + fields => [ 'schedulename', + { field => 'reasonnum', + type => 'select-reason', + reason_class => 'R', + }, + { field => 'basis', + type => 'select', + options => [ keys %FS::commission_schedule::basis_options ], + labels => { %FS::commission_schedule::basis_options }, + }, + { type => 'tablebreak-tr-title', value => 'Billing cycles' }, + { field => 'commissionratenum', + type => 'commission_rate', + o2m_table => 'commission_rate', + m2_label => ' ', + m2_error_callback => $m2_error_callback, + colspan => 2, + }, + ], + labels => { 'schedulenum' => '', + 'schedulename' => 'Name', + 'basis' => 'Based on', + 'commissionratenum' => '', + }, +&> +<%init> + +my $m2_error_callback = sub { + my ($cgi, $object) = @_; + + my @rates; + foreach my $k ( grep /^commissionratenum\d+/, $cgi->param ) { + my $num = $cgi->param($k); + my $cycle = $cgi->param($k.'_cycle'); + my $amount = $cgi->param($k.'_amount'); + my $percent = $cgi->param($k.'_percent'); + if ($cycle > 0) { + push @rates, FS::commission_rate->new({ + 'commissionratenum' => $num, + 'cycle' => $cycle, + 'amount' => $amount, + 'percent' => $percent, + }); + } + } + @rates; +}; + +</%init> diff --git a/httemplate/edit/process/commission_schedule.html b/httemplate/edit/process/commission_schedule.html new file mode 100644 index 000000000..50e0371da --- /dev/null +++ b/httemplate/edit/process/commission_schedule.html @@ -0,0 +1,36 @@ +<& elements/process.html, + 'table' => 'commission_schedule', + 'viewall_dir' => 'browse', + 'process_o2m' => { + 'table' => 'commission_rate', + 'fields' => [qw( cycle amount percent )], + }, + 'precheck_callback' => $precheck, + 'debug' => 1, +&> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $precheck = sub { + my $cgi = shift; + $cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum"; + + my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason'); + if (!$reasonnum) { + $error ||= 'Reason required' + } + $cgi->param('reasonnum', $reasonnum) unless $error; + + # remove rate entries with no cycle selected + foreach my $k (grep /^commissionratenum\d+$/, $cgi->param) { + if (! $cgi->param($k.'_cycle') ) { + $cgi->delete($k); + } + } + + $error; +}; + +</%init> diff --git a/httemplate/elements/commission_rate.html b/httemplate/elements/commission_rate.html new file mode 100644 index 000000000..071ebb1e3 --- /dev/null +++ b/httemplate/elements/commission_rate.html @@ -0,0 +1,68 @@ +% unless ( $opt{'js_only'} ) { + + <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>"> + + <& select.html, + field => "${name}_cycle", + options => [ '', 1 .. 12 ], + option_labels => { + '' => '', + 1 => '1st', + 2 => '2nd', + 3 => '3rd', + map { $_ => $_.'th' } 4 .. 12 + }, + onchange => $onchange, + curr_value => $commission_rate->get("cycle"), + &> + <B><% $money_char %></B> + <& input-text.html, + field => "${name}_amount", + size => 8, + curr_value => $commission_rate->get("amount") + || '0.00', + 'text-align' => 'right' + &> + <B> + </B> + <& input-text.html, + field => "${name}_percent", + size => 8, + curr_value => $commission_rate->get("percent") + || '0', + 'text-align' => 'right' + &><B>%</B> +% } +<%init> + +my( %opt ) = @_; + +my $conf = new FS::Conf; +my $money_char = $conf->config('money_char') || '$'; + +my $name = $opt{'field'} || 'commissionratenum'; +my $id = $opt{'id'} || 'commissionratenum'; + +my $curr_value = $opt{'curr_value'} || $opt{'value'}; + +my $onchange = ''; +if ( $opt{'onchange'} ) { + $onchange = $opt{'onchange'}; + $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/; + $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange + #callbacks should act the same + $onchange = 'onChange="'. $onchange. '"'; +} + +my $commission_rate; +if ( $curr_value ) { + $commission_rate = qsearchs('commission_rate', { 'commissionratenum' => $curr_value } ); +} else { + $commission_rate = new FS::commission_rate {}; +} + +foreach my $field (qw( amount percent cycle)) { + my $value = $cgi->param("${name}_${field}"); + $commission_rate->set($field, $value) if $value; +} + +</%init> diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index 0f98bc960..88c1df3c8 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -672,7 +672,10 @@ $config_cust{'Note classes'} = [ $fsurl.'browse/cust_note_class.html', 'Note cla tie my %config_agent, 'Tie::IxHash', 'Agent types' => [ $fsurl.'browse/agent_type.cgi', 'Agent types define groups of package definitions that you can then assign to particular agents' ], 'Agents' => [ $fsurl.'browse/agent.cgi', 'Agents are resellers of your service. Agents may be limited to a subset of your full offerings (via their type)' ], - 'Agent payment gateways' => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors for agent overrides' ]; + 'Agent payment gateways' => [ $fsurl.'browse/payment_gateway.html', 'Credit card and electronic check processors for agent overrides' ], + 'separator' => '', + 'Commission schedules' => [ $fsurl.'browse/commission_schedule.html', + 'Commission schedules for consecutive billing periods' ], ; tie my %config_sales, 'Tie::IxHash', diff --git a/httemplate/elements/tr-select-reason.html b/httemplate/elements/tr-select-reason.html index 97466f175..9a430222c 100755 --- a/httemplate/elements/tr-select-reason.html +++ b/httemplate/elements/tr-select-reason.html @@ -188,9 +188,8 @@ my $class = $opt{'reason_class'}; my $init_reason; if ( $opt{'cgi'} ) { $init_reason = $opt{'cgi'}->param($name); -} else { - $init_reason = $opt{'curr_value'}; } +$init_reason ||= $opt{'curr_value'}; my $id = $opt{'id'} || $name; $id =~ s/\./_/g; # for edit/part_event |
