add svc_elec_features merged from reference code RT#7643
[freeside.git] / httemplate / edit / usage_elec_manual_input.cgi
1 %my $debug=0; # toggle debug
2 %my( $svcnum,  $pkgnum, $svcpart, $part_svc, $svc_external );
3 %my @field_descriptions = ( 'prev date', 'curr date', 'prev reading',
4 %                           'curr reading', 'tdsp', 'meter mult',
5 %                           'total usage', 'measured demand', 'billed demand',
6 %                           'svcnum', 'entry date', 'meter number' );
7 %my @field_name = qw / prev_date curr_date prev_read curr_read tdsp 
8 %                      meter_multiplier total_usage measured_demand
9 %                      billed_demand svcnum _date meter_number /;
10 %my $date_exception = '(prev_date|curr_date|_date)';
11 %
12 %if ( $cgi->param('error') ) {
13 %  ### handle error call
14 %  $svcnum = $cgi->param('svcnum');
15 %}
16 %else {
17 %
18 %  my($query) = $cgi->keywords;
19 %  $query =~ /^(\d+)$/ or die "unparsable svcnum";
20 %  $svcnum=$1;
21 %
22 %}
23 %
24 %# this is sample data for print in case no previous record of usage_elec
25 %my @sample_data = ( '20070201', '20070228', '10000', '100100', '76.50',
26 %                    '5', '500', '179', '220', "$svcnum", 'NA', '030234972LM');
27 %
28 %### this is where i start
29 %### 
30 %### let gather all the info from usage_elec for the particular 'svcnum'
31 %###
32 %my $p1 = popurl(1);
33 %
34 %print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
35 %      "</FONT>"
36 %  if $cgi->param('error');
37 %
38 %print qq!<FORM ACTION="${p1}process/usage_elec_manual_input.cgi" METHOD=POST>!;
39 %
40 %# print header
41 %print header("Manually Adding Record to usage_elec Table", '');
42 %
43 %#display
44 %#
45 %#
46 <TABLE BORDER=1>
47
48 % # -ctran 04/10/08
49 % # change getting previous 10 record to 13 so we can see at least 1 year 
50 % # worth of transaction
51 % # get the previous 13 usage_elec items
52 % my @usage_obj = FS::usage_elec::query_usage($svcnum, 13); 
53 %
54 % # print the heading
55 % print "<TR bgcolor=#88b2ce class='maintitle'>"
56 %      . join("\n", map("<TH>" . $_ . "</TH>", @field_descriptions))
57 %      . "</TR>\n";
58 %
59 % if (@usage_obj) {
60 %   foreach my $usage (@usage_obj) {
61 %     # fill @usage_ele with data order by @field_name
62 %     my @usage_ele = ();
63 %     foreach my $field (@field_name) {
64 %       if ( $field =~ /$date_exception/ ) {
65 %         # exception handling of converting time to string
66 %         push(@usage_ele,time2str("%Y%m%d",$usage->$field));
67 %       }
68 %       else {
69 %#debug: field= <% $field %> = <% $usage->$field %><BR>
70 %         push(@usage_ele, $usage->$field); 
71 %       }
72 %     }
73 %
74 %     print "<TR bgcolor=#e8e8ea class='mainbody'>" 
75 %          . join("\n", map("<TD>" . $_ . "</TD>", @usage_ele))
76 %          . "</TR>\n";
77 %   } 
78 % }
79 %
80 % ###
81 % ### gathering pre-filled information
82 % ###
83 %
84 % my ($h_prev_date, $h_prev_read, $h_tdsp, $h_meter_multiplier,
85 %     $h_measured_demand, $h_billed_demand, $h_svcnum, $h_meter_number);
86 %
87 % if (@usage_obj) {
88 %  # fill in all the history data
89 %  my $lindex = $#usage_obj;
90 %  $h_prev_date = time2str("%Y%m%d",$usage_obj[$lindex]->curr_date);
91 %  $h_prev_read = $usage_obj[$lindex]->curr_read;
92 %  $h_tdsp = $usage_obj[$lindex]->tdsp;
93 %  $h_meter_multiplier = $usage_obj[$lindex]->meter_multiplier;
94 %  $h_measured_demand = $usage_obj[$lindex]->measured_demand;
95 %  $h_billed_demand = $usage_obj[$lindex]->billed_demand;
96 %  $h_svcnum = $usage_obj[$lindex]->svcnum;
97 %  $h_meter_number = $usage_obj[$lindex]->meter_number;
98 % }
99
100 % # this hash store info to configure the table with text box for input
101 % # size - [int] how big textbox
102 % # value - [alpha numeric] default value of the text box
103 % # extra - [alpha numeric] other option for text box.  I.E. READONLY
104 % #         mean the text box is a readonly
105 % my %field_info = (
106 %                   prev_date => {
107 %                                  'size'     => '8', 
108 %                                  'value'    => $h_prev_date, 
109 %                                },
110 %                   curr_date => { 'size'     => '8' },
111 %                   prev_read => {
112 %                                  'size'     => '8', 
113 %                                  'value'    => $h_prev_read, 
114 %                                },
115 %                   curr_read => { 'size'     => '8' },
116 %                   tdsp      => {
117 %                                  'size'     => '8', 
118 %                                  'value'    => $h_tdsp,
119 %                                },
120 %                   meter_multiplier => {
121 %                                  'size'  => '4', 
122 %                                  'value' => $h_meter_multiplier,
123 %                                       },
124 %                   total_usage => { 'size'     => '6' },
125 %                   measured_demand => {
126 %                                  'size'  => '4', 
127 %                                  'value' => $h_measured_demand,
128 %                                      },
129 %                   billed_demand => {
130 %                                  'size'  => '4', 
131 %                                  'value' => $h_billed_demand,
132 %                                    },
133 %                   svcnum => {
134 %                               'size'     => '6', 
135 %                               'value'    => $svcnum,
136 %                               'extra'    => 'READONLY'
137 %                             },
138 %                   _date => {
139 %                              'size'     => '8', 
140 %                              'value'    => 'N/A',
141 %                              'extra'    => 'READONLY'
142 %                             },
143 %                   meter_number => {
144 %                              'size'     => '14', 
145 %                              'value'    => $h_meter_number,
146 %                                   },
147 %                 );
148 %
149 %
150 % # input box for entry
151 % print qq !<TR bgcolor=#e8e8ea class='mainbody'>!; 
152 % my $input_style = 'STYLE="color:#000000; background-color: #FFFFCC;"';
153 % foreach my $field (@field_name) {
154 %   my $txt = '';
155 %   $txt .= ' SIZE=' . $field_info{$field}->{'size'} 
156 %                                   if (exists($field_info{$field}->{'size'}));
157 %   $txt .= ' VALUE="' . $field_info{$field}->{'value'} . '"' 
158 %                                   if (exists($field_info{$field}->{'value'}));
159 %   $txt .= ' ' . $field_info{$field}->{'extra'} 
160 %                                   if (exists($field_info{$field}->{'extra'}));
161 %   if ($field eq 'meter_multiplier') {
162 %     print qq !
163 %               <TD>
164 %                <TABLE>
165 %                 <TD>
166 %                   <INPUT TYPE="text" $input_style NAME="$field" $txt>
167 %                 </TD>
168 %                 <TD>
169 %                   <INPUT TYPE="checkbox" NAME="ignore_meter_multiplier">Ignore<P>
170 %                 </TD>
171 %                </TABLE>
172 %               </TD>
173 %              !;
174 %   }
175 %   else {
176 %     print qq !
177 %               <TD>
178 %               <INPUT TYPE="text" $input_style NAME="$field" $txt>
179 %               </TD>
180 %              !;
181 %  }
182 % } 
183 % print "</TR>\n";
184
185
186 </TABLE><BR>
187 %print "<BR>measured demand = ",$h_measured_demand,"\n<BR>" if ($debug);
188 %
189 <INPUT TYPE="submit" VALUE="Submit">
190 <INPUT TYPE="Reset" VALUE="Clear">
191 <INPUT TYPE=BUTTON OnClick="$cgi->redirect(popurl(2)."view/svc_external.cgi?$svcnum")"
192        VALUE="Cancel">
193 %
194 % print qq !
195 %   <br><br>
196 %   prev_date, curr_date -
197 %               8 digit in format of yyyymmdd (y-year m-month d-date)<br>
198 %   prev_read, curr_read - positive interger. Also, curr_read > prev_read
199 %                          Unless meter multiplier ignore value is set.  In
200 %                          this case, this condition will be ignore.<br>
201 %   tdsp - an dollar amount w/wo cent<br>
202 %   meter_multiplier - positive integer<br>
203 %   total_usage -
204 %           should equal (total_usage = (prev_read-curr_read) * meter_multiplier)
205 %           unless meter multiplier ignore value is set<br>
206 %   measured_demand - positive integer<br>
207 %   billed_demand - positive integer<br>
208 % !;
209 %
210     </FORM>
211   </BODY>
212 </HTML>
213