default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / change_history_common.html
index 34ce70b..d734053 100644 (file)
@@ -3,6 +3,7 @@
 %   my $bgcolor2 = '#ffffff';
 %   my $bgcolor = '';
 
+<THEAD>
 <TR>
   <TH CLASS="grid" BGCOLOR="#cccccc">User</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Date</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Action</TH>
   <TH CLASS="grid" BGCOLOR="#cccccc">Description</TH>
 </TR>
+</THEAD>
 
 % foreach my $item ( @history ) {
 %   my $history_other = '';
 %   my $act  = $item->history_action;
-%   if ( $act =~ /^replace/ ) {
+%   if ( $act =~ /^replace/ && $item->table ne 'legacy_cust_history' ) {
 %     my $pkey = $item->primary_key;
 %     my $date = $item->history_date;
 %     $history_other = qsearchs({
 %   } else {
 %     $bgcolor = $bgcolor1;
 %   }
+%
+%   ## Create Description and check to see it is not empty, no need to display a record with no description, so skip it.
+%   my $description = '';
+%   if ( $item->table eq 'legacy_cust_history' ) {
+%     $description = $item->description;
+%   } elsif ( $item->table eq 'h_cust_tag' ) {
+%     $description = &{ $h_table_descripsub{$item->table} }( $item, $tables{'cust_tag'} )
+%        if $single_cust && $h_table_descripsub{$item->table};
+%   } else {
+%     my @fields = $item->fields;
+%     push @fields, 'message_dest' if $item->table eq 'h_contact';
+%     $description = join(', ',
+%             map  { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) 
+%                                  ? 'N/A'
+%                                  : $item->get($_);
+%                    $value = time2str($cust_pkg_date_format, $value)
+%                     if $item->table eq 'h_cust_pkg'
+%                     && $cust_pkg_date_fields{$_}
+%                     && $value;
+%
+%                    $value = substr($value, 0, 77).'...' if length($value) > 80;
+%                    $value = encode_entities($value);
+%                    "<I>$_</I>:<B>$value</B>";
+%                  }
+%             grep { $history_other
+%                      ? ( $item->get($_) ne $history_other->get($_) )
+%                      : ( $item->get($_) =~ /\S/ )
+%                  }
+%             grep { ! /^(history|custnum$)/i }
+%                  @fields
+%     );
+%     if ( $single_cust && $h_table_descripsub{$item->table} ) {
+%        $description = &{ $h_table_descripsub{$item->table} }( $item );
+%     }
+%   } #else 
+%  if (!$description) { next; }
 
   <TR>
+
     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-%     my $otaker = $item->history_user;
+%     my $otaker = '';
+%     if ( $item->history_usernum ) {
+%       $access_user{ $item->history_usernum } ||=
+%         FS::access_user->by_key( $item->history_usernum );
+%       $otaker = $access_user{ $item->history_usernum }->username
+%         if $access_user{ $item->history_usernum };
+%     }
+%     $otaker ||= $item->history_user;
 %     $otaker = '<i>auto billing</i>'          if $otaker eq 'fs_daily';
 %     $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
 %     $otaker = '<i>job queue</i>'             if $otaker eq 'fs_queue';
+%     $otaker = '<i>system bootstrap user</i>' if $otaker eq 'fs_bootstrap';
       <% $otaker %>
     </TD>
+
     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
 %     my $d = time2str('%b %o, %Y', $item->history_date );
 %     $d =~ s/ /&nbsp;/g;
       <% $d %>
     </TD>
+
     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
 %     my $t = time2str('%r', $item->history_date );
 %     $t =~ s/ /&nbsp;/g;
 
     <TD ALIGN="center" CLASS="grid" BGCOLOR="<% $bgcolor %>">
 %       my $label = '';
-%       $label = $item->table;
-%       $label =~ s/^h_//;
-%       $label = $tables{$label};
-% if ( $single_cust ) {
-%     $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
-%       if $h_table_labelsub{$item->table};
-% }
+%       if ( $item->table eq 'legacy_cust_history' ) {
+%         $label = $item->item;
+%       } else {
+%         $label = $item->table;
+%         $label =~ s/^h_//;
+%         $label = $tables{$label};
+%         $label = &{ $h_table_labelsub{$item->table} }( $item, $label )
+%           if $single_cust && $h_table_labelsub{$item->table};
+%       }
       <% $label %>
     </TD>
+
     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-      <% $action{$item->history_action} %>
+      <% $action{$item->history_action} || ucfirst($item->history_action) |h %>
     </TD>
+
     <TD ALIGN="left" CLASS="grid" BGCOLOR="<% $bgcolor %>">
-      <% join(', ',
-           map  { my $value = ( $_ =~ /(^pay(info|cvv)|^ss|_password)$/ ) 
-                                ? 'N/A'
-                                : $item->get($_);
-                  $value = time2str($cust_pkg_date_format, $value)
-                   if $item->table eq 'h_cust_pkg'
-                   && $cust_pkg_date_fields{$_}
-                   && $value;
-
-                  $value = substr($value, 0, 77).'...' if length($value) > 80;
-                  $value = encode_entities($value);
-                  "<I>$_</I>:<B>$value</B>";
-                }
-           grep { $history_other
-                    ? ( $item->get($_) ne $history_other->get($_) )
-                    : ( $item->get($_) =~ /\S/ )
-                }
-           grep { ! /^(history|custnum$)/i }
-                $item->fields
-         )
-      %>
+      <% $description %>
     </TD>
+
   </TR>
 
 % }
@@ -125,8 +159,8 @@ die "access deined"
 
 my %action = (
   'insert'      => 'Insert', #'Create',
-  'replace_old' => 'Change&nbsp;from',
-  'replace_new' => 'Change&nbsp;to',
+  'replace_old' => "Change\xA0from",
+  'replace_new' => "Change\xA0to",
   'delete'      => 'Remove',
 );
 
@@ -172,6 +206,18 @@ my $svc_labelsub = sub {
   $label. ': <b>'. encode_entities($item->label($item->history_date)). '</b>';
 };
 
+my $tag_labelsub = sub {
+  my($item, $label) = @_;
+  my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
+  $label. ': <SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
+};
+
+my $contact_labelsub = sub {
+  my($item, $label) = @_;
+  my $contact = qsearchs('h_contact',{ contactnum => $item->contactnum });
+  $label. ': <B>'. encode_entities($contact->first). ' ' . encode_entities($contact->last) . '</B>';
+};
+
 my %h_table_labelsub = (
   'h_cust_pkg'      => $pkg_labelsub,
   'h_svc_acct'      => $svc_labelsub,
@@ -183,6 +229,58 @@ my %h_table_labelsub = (
   'h_svc_external'  => $svc_labelsub,
   'h_svc_phone'     => $svc_labelsub,
   #'h_phone_device'
+  #'h_cust_tag'      => $tag_labelsub,
+  'h_contact'  => $contact_labelsub,
+  'h_cust_contact'  => $contact_labelsub,
+  'h_contact_phone' => $contact_labelsub,
+  'h_contact_email' => $contact_labelsub,
+);
+
+my $tag_descripsub = sub {
+  my($item, $label) = @_;
+  my $part_tag = qsearchs('part_tag',{ tagnum => $item->tagnum });
+  '<SPAN STYLE="background-color: #'.$part_tag->tagcolor.'">'. encode_entities($part_tag->tagname). '</SPAN>';
+};
+
+my $contact_descripsub = sub {
+  my($item, $label) = @_;
+  my $phone_type = qsearchs('phone_type',{ phonetypenum => $item->phonetypenum });
+  my @fields = $item->fields;
+  join(', ',
+    map  {
+           my $value = ( $_ eq "phonetypenum" )
+              ? $item->get($_).' ('.$phone_type->typename.')'
+              : $item->get($_);
+           $value = substr($value, 0, 77).'...' if length($value) > 80;
+           $value = encode_entities($value);
+           "<I>$_</I>:<B>$value</B>";
+         }
+         grep { ! /^(history|custnum$)/i }
+            @fields
+  );
+};
+
+my $discounts = {};
+my $discount_descripsub = sub {
+  my($item) = @_;
+  $pkgpart{$item->pkgpart} ||= qsearchs({
+    'table' => 'part_pkg',
+    'hashref' => {'pkgpart' => $item->pkgpart}
+  })->pkg;
+  my $dnum = $item->discountnum;
+  $discounts->{$dnum} ||= qsearchs({
+    'table'=>'discount',
+    'hashref'=>{'discountnum'=>$dnum}
+  });
+  my $d = $discounts->{$dnum};
+  '(<b>' . encode_entities($d->description_short) . '</b>'
+  . ' on <b>' . encode_entities($pkgpart{$item->pkgpart}) . '</b>)';
+};
+
+my %h_table_descripsub = (
+  'h_cust_pkg_discount' => $discount_descripsub,
+  'h_cust_tag'          => $tag_descripsub,
+  'h_contact_phone'     => $contact_descripsub,
 );
 
 my $cust_pkg_date_format = '%b %o, %Y';
@@ -197,4 +295,6 @@ if ( $curuser->option('history_order') eq 'newest' ) {
   @history = reverse @history;
 }
 
+my %access_user = (); #cache
+
 </%init>