2 <% $cgi->redirect(popurl(2). "timeworked.html?". $cgi->query_string) %>
4 <% $cgi->redirect(popurl(3). "search/timeworked.html?begin=$begin;end=$end;category=$category") %>
9 unless $FS::CurrentUser::CurrentUser->access_right('Time queue');
11 my($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
13 ( my $category = $cgi->param('category') ) =~ /^\w*$/
14 or die 'illegal category';#no need for nice error messages for XSS, just avoid
16 my @acct_rt_transaction;
17 foreach my $transaction (
18 map { /^transactionid(\d+)$/; $1; } grep /^transactionid\d+$/, $cgi->param
20 my $s = "multiplier${transaction}_";
21 my %multipliers = map { /^$s(\d+)$/; $1 => scalar($cgi->param("$s$1")); }
22 grep /^$s\d+$/, $cgi->param;
24 foreach(values %multipliers) {$msum += $_};
26 my $seconds = $cgi->param("seconds$transaction");
28 map { $_ => sprintf("%.0f", $seconds * $multipliers{$_} / $msum) }
32 foreach (values %seconds) {
37 #fudge in some time if we're close
38 if (abs($seconds-$sum) <= $count) {
39 my $adjustment = $seconds-$sum;
40 foreach (keys %seconds) { # explicitly choose one?
41 $seconds{$_} += $adjustment;
45 die "unexpectedly cannot apportion time";
48 foreach my $customer ( grep {$seconds{$_}} keys %seconds ) {
49 push @acct_rt_transaction, new FS::acct_rt_transaction {
50 'custnum' => $customer,
51 'transaction_id' => $transaction,
52 'seconds' => $seconds{$customer},
53 'support' => int( $seconds{$customer} * $msum ),
59 my $error = FS::acct_rt_transaction->batch_insert(@acct_rt_transaction);
60 $cgi->param('error', $error) if $error;