From 1d84feb7fe821b547e211ad03e5c200c8f218797 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 22 Nov 2008 07:10:11 +0000 Subject: [PATCH] billing event cloning --- httemplate/browse/part_event.html | 12 +++++++++- httemplate/edit/elements/edit.html | 49 ++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/httemplate/browse/part_event.html b/httemplate/browse/part_event.html index 4a0582633..674004bc7 100644 --- a/httemplate/browse/part_event.html +++ b/httemplate/browse/part_event.html @@ -144,7 +144,17 @@ my $html_init = #XXX better description 'Events are billing, collection or other actions triggered when certain '. 'customer, invoice, package or other conditions are met.

'. - qq!Add a new event

!; + qq!
!. + qq!Add a new event!. + ' or '. + '

'; my $count_query = 'SELECT COUNT(*) FROM part_event WHERE '. $FS::CurrentUser::CurrentUser->agentnums_sql( diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 934784495..33e4b0dee 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -164,7 +164,7 @@ Example:
- + <% ( $opt{labels} && exists $opt{labels}->{$pkey} ) @@ -172,7 +172,7 @@ Example: : $pkey %> -#<% $object->$pkey() || "(NEW)" %> +#<% ( !$clone && $object->$pkey() ) || "(NEW)" %> % my $tablenum = 0; @@ -313,7 +313,7 @@ Example: % my @existing = (); % if ( $mode eq 'error' ) { % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object ); -% } elsif ( $object->$pkey() ) { # $mode eq 'edit' +% } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone' % @existing = $object->$table(); % warn scalar(@existing). " from $object->$table: ". join('/', @existing) % if $opt{'debug'}; @@ -527,7 +527,7 @@ Example:
-"> +"> @@ -559,8 +559,19 @@ if ( $cgi->param('redirect') ) { $cgi = new CGI($pref); } -my $object; +my %qsearch = ( + 'table' => $table, + 'extra_sql' => ( $opt{'agent_virt'} + ? ' AND '. $curuser->agentnums_sql( + 'null_right' => $opt{'agent_null_right'} + ) + : '' + ), +); + my $mode; +my $object; +my $clone = ''; if ( $cgi->param('error') ) { $mode = 'error'; @@ -572,6 +583,22 @@ if ( $cgi->param('error') ) { &{$opt{'error_callback'}}($cgi, $object, $fields, \%opt ) if $opt{'error_callback'}; +} elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) { + + $mode = 'clone'; + + $clone = $1; + + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } }); + + #XXX document me + &{$opt{'clone_callback'}}($cgi, $object, $fields) + if $opt{'clone_callback'}; + + #$object->$pkey(''); + + $opt{action} ||= 'Add'; + } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing $mode = 'edit'; @@ -584,16 +611,8 @@ if ( $cgi->param('error') ) { $value = $query; } $value =~ /^(\d+)$/ or die "unparsable $pkey"; - $object = qsearchs({ - 'table' => $table, - 'hashref' => { $pkey => $1 }, - 'extra_sql' => ( $opt{'agent_virt'} - ? ' AND '. $curuser->agentnums_sql( - 'null_right' => $opt{'agent_null_right'} - ) - : '' - ), - }); + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }); + warn "$table $pkey => $1" if $opt{'debug'}; -- 2.11.0