blob: 01752e1b70daab25469fc93fb014d0adbede98ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
% if ($error) {
<% $cgi->redirect(popurl(2). "timeworked.html?". $cgi->query_string) %>
% } else {
<% $cgi->redirect(popurl(3). "search/timeworked.html?begin=$begin;end=$end;category=$category") %>
% }
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Time queue');
my($begin, $end) = FS::UI::Web::parse_beginning_ending($cgi);
( my $category = $cgi->param('category') ) =~ /^\w*$/
or die 'illegal category';#no need for nice error messages for XSS, just avoid
my @acct_rt_transaction;
foreach my $transaction (
map { /^transactionid(\d+)$/; $1; } grep /^transactionid\d+$/, $cgi->param
) {
my $s = "multiplier${transaction}_";
my %multipliers = map { /^$s(\d+)$/; $1 => $cgi->param("$s$1"); }
grep /^$s\d+$/, $cgi->param;
my $msum = 0;
foreach(values %multipliers) {$msum += $_};
my $seconds = $cgi->param("seconds$transaction");
my %seconds =
map { $_ => sprintf("%.0f", $seconds * $multipliers{$_} / $msum) }
(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;
}
} else {
die "unexpectedly cannot apportion time";
}
foreach my $customer ( grep {$seconds{$_}} keys %seconds ) {
push @acct_rt_transaction, new FS::acct_rt_transaction {
'custnum' => $customer,
'transaction_id' => $transaction,
'seconds' => $seconds{$customer},
'support' => int( $seconds{$customer} * $msum ),
};
}
}
my $error = FS::acct_rt_transaction->batch_insert(@acct_rt_transaction);
$cgi->param('error', $error) if $error;
</%init>
|