diff options
| author | Mark Wells <mark@freeside.biz> | 2016-08-02 11:41:51 -0700 |
|---|---|---|
| committer | Mark Wells <mark@freeside.biz> | 2016-08-02 13:17:07 -0700 |
| commit | 34c878349988d97957f1d53427896a4d70afb392 (patch) | |
| tree | 44dfc6243fad77753b4e3674ad9d92cd11ddf4d7 /httemplate/edit | |
| parent | 4f3d9e2ef5ce5305363ae426b87ed2b873b355d8 (diff) | |
agent commission schedules for consecutive invoices, #71217
Diffstat (limited to 'httemplate/edit')
| -rw-r--r-- | httemplate/edit/commission_schedule.html | 53 | ||||
| -rw-r--r-- | httemplate/edit/process/commission_schedule.html | 36 |
2 files changed, 89 insertions, 0 deletions
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> |
