[Unsolved][Question] To create a Working time calculator in HelloWorld (call the perl method in javascript/html)

English! place to talk about development, programming and coding
Post Reply
undefined
Znuny newbie
Posts: 5
Joined: 12 Jul 2016, 09:48
Znuny Version: 5.0.9

[Unsolved][Question] To create a Working time calculator in HelloWorld (call the perl method in javascript/html)

Post by undefined »

Hi all, I would like to create a working time calculator.

I espected the user are required to insert the Start day. The system will then calculate the working hours until today.

I had referenced https://otrs.github.io/doc/manual/devel ... -otrs.html to create a Hello World Page.

And i referenced https://otrs.github.io/doc/api/otrs/5.0 ... me.pm.html to calculate the working hour.

The code below is something I trying to add.


AgentHelloWorld.tt

Code: Select all

<p>
    [% Data.HelloWorldText | Translate() | html %]
</p>

<form>
start Year:<br>
<input type="text" id="year">
<br>
start Month:<br>
<input type="text" id="month">
<br>
start Day:<br>
<input type="text" id="day">
<br>
</form>

module/AgentHelloWorld.pm

Code: Select all

$Data{HelloWorldText} = $HelloWorldObject->GetHelloWorldText();
system/HelloWorld.pm

Code: Select all


sub GetHelloWorldText {

use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $TimeObject = $Kernel::OM->Get('Kernel::System::Time');
	  
	my $test; 
	
	my $Created = $TimeObject->Date2SystemTime(
        Year   => 2016,
        Month  => 7,
        Day    => 25,
        Hour   => 0,
        Minute => 0,
        Second => 0,
    );

	
    my ( $Sec, $Min, $Hour, $Day, $Month, $Year, $WDay ) = localtime $Created;    ## no critic
 

my $xml = XML::Simple->new;

    my $WorkingTime = $TimeObject->WorkingTime(
        StartTime => $Created,
        StopTime  => $TimeObject->SystemTime(),
        Calendar  => 1, # '' is default
    );

	
    return $WorkingTime/(60*60);
}
The problem that i faced is i failed to call the perl function from html/javascript.
Are there a way to call the perl function in OTRS?
Or can somebody point me out the next step i should do?

My OTRS version is 5.0.10.

Thanks.
Post Reply