Modulo Custom

Post Reply
remsys
OTRS newbie
Posts: 4
Joined: 11 Aug 2015, 10:28
OTRS Version?: 4.0.11
Real Name: Silvio Balduzzi
Company: RemSys S.r.l.

Modulo Custom

Post by remsys » 05 Sep 2015, 15:30

Buongiorno,

Sto modificando un modulo per fargli eseguire attività personalizzate ma sto riscontrando un problema. Il codice del modulo è:

Code: Select all

# --
# Kernel/Output/HTML/SupportQuota.pm
# Copyright (C) 2001-2014 Deny Dias, http://mexapi.macpress.com.br/
# --
# 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::Output::HTML::SupportQuota;

use strict;
use warnings;

use Kernel::System::CustomerUser;

our @ObjectDependencies = qw(
    Kernel::Config
    Kernel::System::DB
    Kernel::Output::HTML::Layout
    Kernel::System::Web::Request
);

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

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

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

    my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
    my $ParamObject  = $Kernel::OM->Get('Kernel::System::Web::Request');	

    # get data
    my %Data = ();
	
	# leggo IDCliente
	my $SQL = "SELECT customer_id FROM ticket WHERE id=35742";
	$Kernel::OM->Get('Kernel::System::DB')->Prepare(
        SQL   => $SQL, Limit => 1,
    );
	while (my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray()) {
		$Data{IDCliente} = $Row[0];
	}	
	
	# leggo Credito acquistato
	my $SQL = "SELECT acquistato FROM customer_company WHERE customer_id='".$Data{IDCliente}."'";
	$Kernel::OM->Get('Kernel::System::DB')->Prepare(SQL => $SQL, Limit => 15);
	while (my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray()) {
		$Data{Acquistato} = $Row[0];
	}
	
	# leggo Credito consumato
	my $SQL = "SELECT consumato FROM customer_company WHERE customer_id='".$Data{IDCliente}."'";
	$Kernel::OM->Get('Kernel::System::DB')->Prepare(SQL => $SQL, Limit => 15);
	while (my @Row = $Kernel::OM->Get('Kernel::System::DB')->FetchrowArray()) {
		$Data{Consumato} = $Row[0];
	}	

    # format and calculate remaining data
    my $Acquistato  = sprintf '%.1f', $Data{Acquistato};
    my $Consumato      = sprintf '%.1f', $Data{Consumato};
    my $Disponibile = sprintf '%.1f', $Data{Acquistato} - $Data{Consumato};

    my $Template = q~
            <div class="WidgetSimple">
                <div class="Header">
                    <h2>[% Translate("Stato credito cliente (da Time)") | html %]</h2>
                </div>
                <div class="Content">
                    <fieldset class="TableLike FixedLabelSmall Narrow">
                        <label>[% Translate("Acquistato") | html %]:</label>
                        <p class="Value">[% Data.Acquistato | html %]</p>
                        <div class="Clear"></div>
                        <label>[% Translate("Consumato") | html %]:</label>
                        <p class="Value">[% Data.Consumato | html %]</p>
                        <div class="Clear"></div>
                        <label>[% Translate("Disponibile") | html %]:</label>
                        <p class="Value">[% Data.Disponibile | html %]</p>
                        <div class="Clear"></div>
                    </fieldset>			
                </div>
            </div>
    ~;

    my $HTML = $LayoutObject->Output(
        Template => $Template,
        Data     => {
            Disponibile  => $Disponibile,
            Consumato       => $Consumato,
            Acquistato => $Acquistato
        },
    );

    # add information
    ${ $Param{Data} } =~ s{ (\[\% \s+ RenderBlockStart\("CustomerTable"\) \s+ \%\]) }{ $HTML $1 }ixms;

    return $Param{Data};
}

1;
Tutto funziona se alla riga my $SQL = "SELECT customer_id FROM ticket WHERE id=35742"; inserisco a mano l'id del ticket ma non riesco a capire come farmi passare il parametro TicketID direttamente dal sistema.

Qualcuno ha qualche consiglio a riguardo?

Grazie mille

Silvio

Post Reply