View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Supportez nous sur Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - Why does WorkElement save work for session user ? - ProjeQtOr

Prochaines sessions de formation

Les prochaines formations et démonstrations sont ouvertes, inscrivez-vous rapidement !

 

Démonstration de ProjeQtOr

(gratuit, sur inscription)

Mardi 23 avril (10h30-12h)

Jeudi 16 mai (16h-17h30)

Jeudi 13 juin (10h30-12h)

 
 

Planifiez avec ProjeQtOr

3 et 4 avril (9h - 12h30)

 
 

Administrez avec ProjeQtOr

10 et 11 avril (9h - 12h30)

 

 

 
 

Why does WorkElement save work for session user ?

More
16 Avr 2021 22:30 - 16 Avr 2021 22:30 #1 by Baryhobal
Hello,

While developing my telegram bot plugin, I stumbled upon a problem which seemed really strange at first. I implemented a button to start/stop work on tickets through the bot. However, the WorkElement always saves the worktime to the session user (a user I created for the bot) instead of the user I set by manually changing its idUser value. I looked a bit further in the WorkElementMain.php and found this in the save function:
(lines 145 and 214 to 222, V9.1.2)
$user = getSessionUser();

...

// If realWork has changed (not through Dispatch screen), update the work
if ($diff != 0) {
  // Set work to Ticket
  $idx = - 1;
  // Will retrive work for current WorkElement, Current resource
  $crit = array (
      'idWorkElement' => $this->id,
      'idResource' => $user->id 
  );

This seems a bit strange to me. Why do you you use the session user instead of the user currently working on the ticket ? Is this intended or a bug ? If it is intended, do you know how I could manage what I want to do, that is starting and stopping work for another user ?

Thanks in advance for your reply
Last edit: 16 Avr 2021 22:30 by Baryhobal. Reason: Typo in title

Please Connexion or Create an account to join the conversation.

More
18 Avr 2021 20:23 #2 by babynus
No, it is normal if you concider Ticket screen.
There, you have visibility on WorkElement fields : estimated work, and real work.
If current user changes real work, it is automatically converted into real work (table work) and concidered it is some work now for current user.
Changing real work for another user, or another day requires to use Dispatch Work feature (see "saveDispatchWork.php)

 

Babynus
Administrator of ProjeQtOr web site

Please Connexion or Create an account to join the conversation.

More
23 Avr 2021 21:49 #3 by Baryhobal
Good evening,

Thank you for your message.

I've looked at
saveDispatchWork.php
and it seems indeed to be what I need. I've tried to copy the important elements of the script to adapt it to my needs, but I still have some issues. I can succesfully create a new Work object and it updates the field in the "Dispatch" menu but I can't get it to update the total time on the ticket. I thought maybe
ProjectPlanningElement::updateSynthesis
was responsible for this but even after adding the line, it still didn't work. How is it supposed to update the total work time outside of the dispatch menu ?

Here are some screenshots to illustrate my problem:
Incorrect total work time displayed in the ticket
 

Correct work details in dispatch menu
 
Attachments:

Please Connexion or Create an account to join the conversation.

More
23 Avr 2021 21:55 #4 by Baryhobal
Here is what I've got to stop work and save the appropriate work time:
//$element is the element to which it should save work, for exemple a ticket
//$userId is the Resource/User id to which work should be attributed

$startTime = $element->WorkElement->ongoingStartDateTime;
$stopTime = date ( 'Y-m-d H:i:s' );
$workTime = workTimeDiffDateTime ( $startTime, $stopTime );

Sql::beginTransaction();
$saveDispatchMode=true;

$work = new Work();

$work->setDates(date("Y-m-d"));
$work->idResource=$userId;
$work->idProject=$element->idProject;

if ($element->idActivity) {
    $work->refType = "Activity";
    $work->refId=$element->idActivity;
} else {
    $work->refType = $class;
    $work->refId = $id;
}

$newWork=Work::convertImputation($workTime);
$diff=$newWork;
$work->work=$newWork;
$work->idWorkElement=$element->WorkElement->id;
$work->dailyCost=null; // set to null to force refresh 
$work->cost=null;

$ass=WorkElement::updateAssignment($work, $diff);
$work->idAssignment=($ass)?$ass->id:null;

$resWork = $work->save();

if ($resWork) {
    $status = getLastOperationStatus ( $resWork );
    if ($status=='OK') {
        error_log("OK");
        if ($ass) error_log($ass->saveWithRefresh());
    } else if ($status=='ERROR' or $status=='INVALID') {
        error_log("Error when stopping work: ".$resWork);
        break;
    }
}

ProjectPlanningElement::updateSynthesis('Project',$element->idProject);
Sql::commitTransaction();

$element->WorkElement->idUser = null;
$element->WorkElement->ongoing = 0;
$element->WorkElement->ongoingStartDateTime = null;

$element->WorkElement->save();

Please Connexion or Create an account to join the conversation.

More
28 Avr 2021 15:55 #5 by Baryhobal
I also looked at PlanningElement.php, Assignment.php, Work.php and projeqtorWork.js but I haven't found anything that would solve the problem. I suppose I must have forgotten a line or missed another part of the process but I don't know which.

Can you see what I'm doing wrong ? I would be very thankful because this has kept bothering for the last few days

Please Connexion or Create an account to join the conversation.

More
02 Mai 2021 11:49 #6 by babynus
I don't get what's wrong now.
Please explain, what you now get, and what is still not working as expected.

Babynus
Administrator of ProjeQtOr web site

Please Connexion or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.076 seconds

Paramétrages de cookies

×

Cookies fonctionnels

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Veuillez vous connecter pour voir vos activités!

Autres cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.