From 1293d137b061f097190eda53e4e78214e18832e6 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 16 Aug 2007 13:40:46 +0000 Subject: support hours 'usage' tracking for our own internal use (#1733) --- httemplate/misc/batch-cust_pay.html | 379 +------------------------- httemplate/misc/elements/customer-table.html | 387 +++++++++++++++++++++++++++ httemplate/misc/process/timeworked.html | 47 ++++ httemplate/misc/timeworked.html | 77 ++++++ 4 files changed, 519 insertions(+), 371 deletions(-) create mode 100644 httemplate/misc/elements/customer-table.html create mode 100644 httemplate/misc/process/timeworked.html create mode 100755 httemplate/misc/timeworked.html (limited to 'httemplate/misc') diff --git a/httemplate/misc/batch-cust_pay.html b/httemplate/misc/batch-cust_pay.html index d85f3b6c3..f2f446001 100644 --- a/httemplate/misc/batch-cust_pay.html +++ b/httemplate/misc/batch-cust_pay.html @@ -1,8 +1,5 @@ <% include("/elements/header.html", 'Quick payment entry', - menubar( - 'Main Menu' => $p, #popurl(1), - ), - ( $cgi->param('error') ? '' : 'onload="addRow()"' ), + menubar( 'Main Menu' => $p ), ) %> % if ( $cgi->param('error') ) { @@ -16,284 +13,13 @@ - - - - - - - - - - - -% my $row = 0; -% if ( $cgi->param('error') ) { -% my $param = $cgi->Vars; -% -% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { - - - - - - - - - - - - - - - -% } -% } - - -
Cust #CustomerAmountCheck #
- " rownum="<% $row %>"> - - - " rownum="<% $row %>"> - - - - - $" > - - " > - -% if ( $param->{"error$row"} ) { - - Error: <% $param->{"error$row"} %> -% } - -
+<% include( "elements/customer-table.html", + header => [ '', 'Amount', 'Check #', '' ], + fields => [ sub {'$'}, 'paid', 'payinfo', 'error', ], + types => [ 'immutable', '', '', 'immutable', ], + sizes => [ 0, 8, 10, 0, ], + param => { () }, + ) %> @@ -302,94 +28,5 @@ - - -<% include('/elements/xmlhttp.html', - 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', - 'subs' => [qw( custnum_search smart_search )], - ) -%> - - - diff --git a/httemplate/misc/elements/customer-table.html b/httemplate/misc/elements/customer-table.html new file mode 100644 index 000000000..fc298b03e --- /dev/null +++ b/httemplate/misc/elements/customer-table.html @@ -0,0 +1,387 @@ +% # options example... +% # +% # #listrefs... +% # 'header' => [ '#', 'Item' ], +% # 'fields' => [ +% # 'column', +% # sub { my ($row,$param) = @_; $param->{"column$row"}; }, +% # ], +% # 'sizes' => [], # sizes ignored for immutable +% # 'types' => ['immutable', ''], # immutable or ''/text +% # 'param' => { column0 => 1 }, # preset column of row 0 to 1 +% # + + + + + + + + +% foreach my $header ( @{$opt{header}} ) { + +% } + +% my $row = 0; +% for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { + + + + + + + +% my $col = 0; +% foreach my $field ( @{$opt{fields}} ) { +% my $value; +% if ( ref($field) eq 'CODE' ) { +% $value = &{$field}($row,$param); +% } else { +% $value = $param->{"$field$row"}; +% } +% my $name = (ref($field) eq 'CODE') ? "column${col}_$row" : "$field$row"; +% my $size = $sizes->[$col] || 10; + +% $col++; +% } + + +% } + + +
Cust #Customer<% $header %>
+ " rownum="<% $row %>"> + + + " rownum="<% $row %>"> + + + + +% if (! $types->[$col] || $types->[$col] eq 'text') { + +% } elsif ($types->[$col] eq 'immutable') { + <% $value %> + +% } else { + Cannot represent unknown type: <% $types->[$col] %> +% } +
+ +<% include('/elements/xmlhttp.html', + 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', + 'subs' => [qw( custnum_search smart_search )], + ) +%> + + + +<%init> + +my(%opt) = @_; + +$opt{prefix} = '' unless defined $opt{prefix}; +$opt{prefix} .= '_' if $opt{prefix}; + +my $types = $opt{'types'} ? [ @{$opt{'types'}} ] : []; +my $sizes = $opt{'sizes'} ? [ @{$opt{'sizes'}} ] : []; + +my $param = $opt{param}; +$param = $cgi->Vars if $cgi->param('error'); + + diff --git a/httemplate/misc/process/timeworked.html b/httemplate/misc/process/timeworked.html new file mode 100644 index 000000000..078d645d1 --- /dev/null +++ b/httemplate/misc/process/timeworked.html @@ -0,0 +1,47 @@ +% if ($error) { +<% $cgi->redirect(popurl(2). "timeworked.html?". $cgi->query_string) %> +% } else { +<% $cgi->redirect(popurl(3). "search/timeworked.html") %> +% } +<%init> + +my %multipliers = map { /^custnum(\d+)$/; ($cgi->param("custnum$1") => $cgi->param("multiplier$1")); } + grep /^custnum\d+$/, $cgi->param; + +my @svc_acct_rt_transaction; +foreach my $transaction ( + map { /^transactionid(\d+)$/; $1; } grep /^transactionid\d+$/, $cgi->param +) { + my $seconds = $cgi->param("seconds$transaction"); + my %seconds = map { $_ => sprintf("%.0f", $seconds * $multipliers{$_}) } + (keys %multipliers); + my $sum = 0; + my $count = 0; + foreach (values %seconds) { + $sum += $_; + $count++; + } + + #fudge in some time if we're close + if (abs($seconds-$sum) <= $count) { + my $adjustment = $seconds-$sum; + foreach (keys %seconds) { # explicitly choose one? + $seconds{$_} += $adjustment; + last; + } + } + + foreach my $customer ( grep {$seconds{$_}} keys %seconds ) { + push @svc_acct_rt_transaction, new FS::svc_acct_rt_transaction { + 'custnum' => $customer, + 'transaction_id' => $transaction, + 'seconds' => $seconds{$customer}, + }; + } + +} + +my $error = FS::svc_acct_rt_transaction->batch_insert(@svc_acct_rt_transaction); +$cgi->param('error', $error) if $error; + + diff --git a/httemplate/misc/timeworked.html b/httemplate/misc/timeworked.html new file mode 100755 index 000000000..2b288f233 --- /dev/null +++ b/httemplate/misc/timeworked.html @@ -0,0 +1,77 @@ +<% include('/elements/header.html', $title, '' ) %> + +% if ( $cgi->param('error') ) { + Error: <% $cgi->param('error') %> +

+% } + +
+ +

+<% include("elements/customer-table.html", header => [ 'Multiplier' ], + fields => [ 'multiplier' ], + param => { %param }, + ) %> + +
+ +
+
+ +for transactions/tickets: + + +% foreach ( sort { $a <=> $b } keys %ticket ) { + + + + " > + +% } + +
<% $_ %><% $ticket{$_} %>
+
+ + + +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Time queue'); + +my($svcnum, %ticket, %customers, %param); +my $title = 'Assign Time Worked'; + +RT::Init(); + +my $CurrentUser = RT::CurrentUser->new(); +$CurrentUser->LoadByName($FS::CurrentUser::CurrentUser->username); + +foreach my $id ( map { /^transactionid(\d+)$/; $1; } + grep /^transactionid\d+$/, $cgi->param) { + my $transaction = new RT::Transaction($CurrentUser); + $transaction->Load($id); + my $ticket = new RT::Ticket($CurrentUser); + $ticket->Load($transaction->ObjectId); + $ticket{$id} = $ticket->Subject; + foreach my $customerURI ( + grep { $_->Resolver->{'fstable'} eq 'cust_main' } + grep { $_->Scheme eq 'freeside' } + map { $_->TargetURI } + @{ $ticket->_Links('Base')->ItemsArrayRef } + ) { + $customers{$customerURI->Resolver->AsString} = 1; + } +} + +my $row = 0; +foreach ( keys %customers ) { + my ($number, $name) = split(':', $_, 2); + $param{"custnum$row"} = $number; + $param{"customer$row"} = $name; + $param{"multiplier$row"} = sprintf("%.2f", 1/scalar(keys(%customers))); + $row++; +} + + + -- cgit v1.2.1