summaryrefslogtreecommitdiff
path: root/httemplate/misc/timeworked.html
blob: 672fad8d6306bec83eb307831dfd7d6a61a428f3 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<% include('/elements/header.html', $title, '' ) %>

<% include('/elements/error.html') %>

<FORM NAME="timeworked_form" ACTION="<% popurl(1) %>process/timeworked.html" METHOD=POST>

<TABLE CELLSPACING="2" CELLPADDING="2" RULES="groups" FRAME="hsides">

  <THEAD>
    <TR>
      <TH COLSPAN="2">Ticket</TH>
      <TH>Hours</TH>
      <TH COLSPAN="2">Customer</TH>
      <TH>Multiplier</TH>
    </TR>
  </THEAD>

  <TBODY>

%   foreach my $tr_id ( keys %ticketmap ) {
%     my (@customers) = @{$customers{$ticketmap{$tr_id}}};
%     next unless @customers;
%     my $default_multiplier = sprintf("%.2f", 1/@customers);
%     my ($custnum, $name) = split(':', pop @customers, 2);
%     my $link = $p. 'rt/Ticket/Display.html?id='. $ticketmap{$tr_id}.
%                    '#txn-'. $tr_id;
%     my $clink = $p. 'view/cust_main.cgi?'. $custnum;

      <TR>
        <TD><a href="<% $link %>"><% $ticketmap{$tr_id} %></a></TD>
        <TD><a href="<% $link %>"><% $ticket{$ticketmap{$tr_id}} |h %></a></TD>

%       my $seconds = 0;
%       if ( $cgi->param("seconds$tr_id") =~ /^(\d+)$/ ) {
%         $seconds = $1;
%       }

        <TD><% sprintf("%0.2f", $seconds/3600) %></TD>
        <TD ALIGN="right"><a href="<% $clink %>"><% $custnum %></a></TD>
        <TD ALIGN="right"><a href="<% $clink %>"><% $name %></a></TD>
        <TD>
          <INPUT TYPE="hidden" NAME="transactionid<%$tr_id%>" VALUE="1" >
          <INPUT TYPE="hidden" NAME="seconds<%$tr_id%>" VALUE="<% $seconds %>" >

%         my $multiplier = $default_multiplier;
%         my $mult_paramname = "multiplier${tr_id}_$custnum";
%         if ( $cgi->param($mult_paramname) =~ /^\s*([\d\.]+)\s*$/ ) {
%           $multiplier = $1;
%         }

          <INPUT TYPE="text" NAME="<% $mult_paramname %>" SIZE="5" VALUE="<% $multiplier %>" >
        </TD>
      </TR>

%     foreach ( @customers ) {
%       ($custnum, $name) = split(':', $_, 2);
%       $clink = $p. 'view/cust_main.cgi?'. $custnum;

        <TR>
          <TD ALIGN="right" COLSPAN="4" ><a href="<% $clink %>"><% $custnum %></a></TD>
          <TD ALIGN="right"><a href="<% $clink %>"><% $name %></a></TD>
          <TD>

%           $multiplier = $default_multiplier;
%           $mult_paramname = "multiplier${tr_id}_$custnum";
%           if ( $cgi->param($mult_paramname) =~ /^\s*([\d\.]+)\s*$/ ) {
%             $multiplier = $1;
%           }

            <INPUT TYPE="text" NAME="<% $mult_paramname %>" SIZE="5" VALUE="<% $multiplier %>" >

          </TD>

        </TR>

%     }
%   }

  </TBODY>

</TABLE>

<BR>

<INPUT TYPE="hidden" NAME="begin" VALUE="<% $cgi->param('begin') |h %>">
<INPUT TYPE="hidden" NAME="end"   VALUE="<% $cgi->param('end')   |h %>">

<INPUT TYPE="submit" NAME="submit" VALUE="<% $title %>">
</FORM>

<% include('/elements/footer.html') %>

<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Time queue');

my(%ticketmap, %ticket, %customers); 
my $title = 'Assign Time Worked';
tie %ticketmap, 'Tie::IxHash';

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);
  $ticketmap{$id} = $transaction->ObjectId;
  unless(exists($ticket{$ticketmap{$id}})) {
    my $ticket = new RT::Ticket($CurrentUser);
    $ticket->Load($ticketmap{$id});
    $ticket{$ticketmap{$id}} = $ticket->Subject;
    $customers{$ticketmap{$id}} =
                            [ map  { $_->Resolver->AsString }
                              grep { $_->Resolver->{'fstable'} eq 'cust_main' }
                              grep { $_->Scheme eq 'freeside' } 
                              map  { $_->TargetURI } 
                                @{ $ticket->_Links('Base')->ItemsArrayRef } 
                            ];
                            
  }
}

</%init>