diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-08-30 00:48:08 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-08-30 00:48:08 -0700 |
commit | 7c9457296c5dd8985eda5a8325ba1254223ec953 (patch) | |
tree | 5020c5dbc196f581f7607342f7b2d35b28db5273 /httemplate/edit/process/agent.cgi | |
parent | c19fc5ead7b7eb700ced64658378ac934b1bc98d (diff) |
commissions per agent and package class, RT#18232
Diffstat (limited to 'httemplate/edit/process/agent.cgi')
-rwxr-xr-x | httemplate/edit/process/agent.cgi | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/httemplate/edit/process/agent.cgi b/httemplate/edit/process/agent.cgi index e776d281c..034c4cc50 100755 --- a/httemplate/edit/process/agent.cgi +++ b/httemplate/edit/process/agent.cgi @@ -1,11 +1,12 @@ <% include( 'elements/process.html', - 'table' => 'agent', - 'viewall_dir' => 'browse', - 'viewall_ext' => 'cgi', - 'process_m2m' => { 'link_table' => 'access_groupagent', - 'target_table' => 'access_group', - }, - 'edit_ext' => 'cgi', + 'table' => 'agent', + 'viewall_dir' => 'browse', + 'viewall_ext' => 'cgi', + 'process_m2m' => { 'link_table' => 'access_groupagent', + 'target_table' => 'access_group', + }, + 'edit_ext' => 'cgi', + 'noerror_callback' => $process_agent_pkg_class, ) %> <%init> @@ -18,4 +19,30 @@ if ( FS::Conf->new->exists('disable_acl_changes') ) { die "shouldn't be reached"; } +my $process_agent_pkg_class = sub { + my( $cgi, $agent ) = @_; + + #surprising amount of false laziness w/ edit/agent.cgi + my @pkg_class = qsearch('pkg_class', { 'disabled'=>'' }); + foreach my $pkg_class ( '', @pkg_class ) { + my %agent_pkg_class = ( 'agentnum' => $agent->agentnum, + 'classnum' => $pkg_class ? $pkg_class->classnum : '' + ); + my $agent_pkg_class = + qsearchs( 'agent_pkg_class', \%agent_pkg_class ) + || new FS::agent_pkg_class \%agent_pkg_class; + + my $param = 'classnum'. $agent_pkg_class{classnum}; + + $agent_pkg_class->commission_percent( $cgi->param($param) ); + + my $method = $agent_pkg_class->agentpkgclassnum ? 'replace' : 'insert'; + + my $error = $agent_pkg_class->$method; + die $error if $error; #XXX push this down into agent.pm w/better/transactional error handling + + } + +}; + </%init> |