How to limit Customermap to show ONLY open tickets

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
hmmmm3
Znuny newbie
Posts: 57
Joined: 17 Feb 2012, 07:48
Znuny Version: 3

How to limit Customermap to show ONLY open tickets

Post by hmmmm3 »

I am not a perl programmer but wanted to give others a starting point on how to reprogram the Google CustomerMap to show only open tickets. I was often confused by this product because it shows everything. When you look at my code, please offer changes that may improve efficiency .

The only file that you need to edit is: GmapsCustomer.pm After you edit the file you will need to re-run the cron tab. My complete code is coped in the below:

Key changes: 1.) add the logic to find the customer info associated with open tickets.

Let me know if you have questions.


Code: Select all

# --
# Kernel/System/GMapsCustomer.pm - a GMaps customer
# Copyright (C) 2001-2011 Martin Edenhofer, http://edenhofer.de/
# --
# $Id: $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::System::GMapsCustomer;

use strict;
use warnings;

use Kernel::System::CustomerUser;
use Kernel::System::GMaps;
use Kernel::System::Time;
use Kernel::System::Ticket;
use Kernel::System::JSON;
use Kernel::System::VirtualFS;

use vars qw(@ISA $VERSION);
$VERSION = qw($Revision: 1.1 $) [1];

=head1 NAME

Kernel::System::GMapsCustomer - a GMaps customer lib

=head1 SYNOPSIS

All GMaps customer functions.

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create an object

    use Kernel::Config;
    use Kernel::System::Encode;
    use Kernel::System::Log;
    use Kernel::System::Main;
    use Kernel::System::GMapsCustomer;

    my $ConfigObject = Kernel::Config->new();
    my $EncodeObject = Kernel::System::Encode->new(
        ConfigObject => $ConfigObject,
    );
    my $LogObject = Kernel::System::Log->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
    );
    my $MainObject = Kernel::System::Main->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
        LogObject    => $LogObject,
    );
    my $GMapsCustomerObject = Kernel::System::GMapsCustomer->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
        LogObject    => $LogObject,
        MainObject   => $MainObject,
    );

=cut

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    # check needed objects
    for my $Object (qw(DBObject ConfigObject LogObject MainObject EncodeObject)) {
        $Self->{$Object} = $Param{$Object} || die "Got no $Object!";
    }

    $Self->{GMapsObject}        = Kernel::System::GMaps->new( %{$Self} );
    $Self->{CustomerUserObject} = Kernel::System::CustomerUser->new( %{$Self} );
    $Self->{TimeObject}         = Kernel::System::Time->new( %{$Self} );
    $Self->{TicketObject}       = Kernel::System::Ticket->new( %{$Self} );
    $Self->{JSONObject}         = Kernel::System::JSON->new( %{$Self} );
    $Self->{VirtualFSObject}    = Kernel::System::VirtualFS->new( %{$Self} );

    # required attributes
    $Self->{RequiredAttributes} = ['UserCity'];

    # attribute map
    $Self->{MapAttribtes} = {
        'UserStreet'  => 'UserStreet',
        'UserCity'    => 'UserCity',
        'UserCountry' => 'UserCountry',
    };

    # open ticket state types
    $Self->{StateType} = [ 'new', 'open', 'pending reminder', 'pending auto' ];
     #$Self->{StateType} = [ 'Open'];

    return $Self;
}

=item DataBuild()

return the content of requested URL

    my $Success = $GMapsCustomerObject->DataBuild();

=cut

sub DataBuild {
    my ( $Self, %Param ) = @_;

    my %List = $Self->{CustomerUserObject}->CustomerUserList(
        Valid => 1,
    );
    
   #Find tickets which meet my status requirements - as defined above
    my @ArrayResults = $Self->{TicketObject}->TicketSearch(
         Result            => 'ARRAY',
         StateType         => $Self->{StateType},
         UserID            => 1,
        );

  
  my @Data;
  my $Counter      = 0;
  my $CounterLimit = 100_000;      
  USER:     
    foreach my $MyTicketID(@ArrayResults){
	    
         #Get the ticketID associated with the selected tickets
	  my %TempTicketArray = $Self->{TicketObject}->TicketGet(
        TicketID => $MyTicketID,
                
      );
      [color=#FF0000] #Find the customer info associated with the ticket[/color]
   	my %Customer1 = $Self->{CustomerUserObject}->CustomerUserDataGet(
             User => $TempTicketArray{CustomerID},
        );
        
       # geo lookup
      
        my $Query1;
        for my $KeyOrig (qw(UserStreet UserCity UserCountry)) {
            my $Key = $Self->{MapAttribtes}->{$KeyOrig};
            next if !$Customer1{$Key};
            chomp $Customer1{$Key};
            if ($Query1) {
                $Query1 .= ', ';
            }
            $Query1 .= $Customer1{$Key};
        }
          my %Response = $Self->{GMapsObject}->Geocoding(
            Query => $Query1,
          );
        

        next if !%Response;

        # required check
        next if $Response{Status} !~ /200/;
        next if $Response{Accuracy} < 6;

        # counter check
        $Counter++;
        last USER if $Counter == $CounterLimit;

        my $Count = $Self->{TicketObject}->TicketSearch(
            Result            => 'COUNT',
            StateType         => $Self->{StateType},
            CustomerUserLogin => $TempTicketArray{CustomerID},
            UserID            => 1,
        );
        push @Data, [ $Response{Latitude}, $Response{Longitude}, $TempTicketArray{CustomerID}, $Count ];
    }

    if ( !@Data ) {
        $Self->{LogObject}->Log(
            Priority => 'error',
            Message =>
                "No Customer Data found with 'UserCity' attribute (UserStreet, UserCity and UserCountry is used in generel)!",
        );
        return;
    }

    my $Content = $Self->{JSONObject}->Encode(
        Data => \@Data,
    );

    $Self->{VirtualFSObject}->Delete(
        Filename        => '/CMapsCustomerMap/Data.json',
        DisableWarnings => 1,
    );

    my $Success = $Self->{VirtualFSObject}->Write(
        Content  => \$Content,
        Filename => '/CMapsCustomerMap/Data.json',
        Mode     => 'utf8',
    );
    return if !$Success;
    return scalar @Data;
}

=item DataRead()

read data and return json string

    my $ContentJSONRef = $GMapsCustomerObject->DataRead();

=cut

sub DataRead {
    my ( $Self, %Param ) = @_;

    my %File = $Self->{VirtualFSObject}->Read(
        Filename        => '/CMapsCustomerMap/Data.json',
        Mode            => 'utf8',
        DisableWarnings => 1,
    );
    return '{}' if !%File;
    return $File{Content};
}
1;

=back

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (http://otrs.org/).

This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see http://www.gnu.org/licenses/agpl.txt.

=cut

=head1 VERSION

$Revision: 1.1 $ $Date: 2009/06/10 19:20:24 $

=cut
ineknott33
Znuny newbie
Posts: 1
Joined: 29 Feb 2012, 03:24
Znuny Version: Otterhub
Real Name: Katherine Knott

Re: How to limit Customermap to show ONLY open tickets

Post by ineknott33 »

I am really having the same problem, and thanks for putting this info here..Will try to manage and use the info given.
Rotyn
Znuny newbie
Posts: 68
Joined: 21 Aug 2012, 17:11
Znuny Version: 3.3.5
Real Name: Rudy

Re: How to limit Customermap to show ONLY open tickets

Post by Rotyn »

The coolest thing I could image for this map:

To add two dropdown fields to toggle between:
  • all tickets / all open tickets
  • all queues, my queues, specific queue
Important: parameters should be forwarded by the URL.....so they different views could be used as well on other places (hardcoded)

Regards
Rudy
Testing & Productive: OTRS::ITSM 3.3.5 on CentOS 6.5 and MySQL
Packages: All included
hmmmm3
Znuny newbie
Posts: 57
Joined: 17 Feb 2012, 07:48
Znuny Version: 3

Re: How to limit Customermap to show ONLY open tickets

Post by hmmmm3 »

Please let me know when you have added this mods....I would love to see them. :) :D

I think they would be great too!!!
Post Reply