Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#813880
Hi Everyone,

I would like to set the due date for the next task based on a date entered by the user in a Dynaform. The due date must take into consideration the current calendar associated with the task.

For example, the user enters an initial date of 01-Apr-2018 in Step 1. The due date of step 2 must take into account the calendar associated with Step 1 and apply the correct due date:

The timing control of Step 1 is set up as follows:

Task Duration: 7 days
Count Days by: Work Days
Calendar: Work Days showing public holidays

Step 1 may be executed on 01-Apr-2018 or some time later. The due date of task 2 must reflect the correct date from the initial date.

Is this possible with PM3.2?

Thanks
#813893
There is a better way than using a date control in your dynaform, you just need to check the option "Allow users to change the task duration in run-time" in your task properties:

Image
When that option is checked, your users will be able to select the task duration, count days, and calendar before the case is routed to the next user:

Image

You can find more information about this here: http://wiki.processmaker.com/3.2/Tasks#Properties
#813894
You can use Calendar::calculateDate(), which is defined in workflow/engine/classes/class.calendar.php, to calculate the Due Date for a task using the configured calendar, but it is easier to simply get the due date for your Task1 since it already includes the time calculation using the calendar.

Example:
In your Task1, create a "Set Date" Dynaform with a datetime field whose variable is named "task2DueDate".

Then create a trigger that will set the minimum, maximum and default dates on the "task2DueDate" field:
Code: Select all
$c = new Cases();
$aCase = $c->loadCase(@@APPLICATION, @%INDEX);
$task1DueDate = $aCase['DEL_TASK_DUE_DATE'];
@@task2MinDueDate = date("Y-m-d H:i:s", strtotime($task1DueDate));
@@task2DefaultDueDate = date("Y-m-d H:i:s", strtotime($task1DueDate . ' +1 day'));
@@task2MaxDueDate = date("Y-m-d H:i:s", strtotime($task1DueDate . ' +10 days')); 
Set this trigger to fire before your Dynaform containing the "task2DueDate" datetime field.

Then set those variables in the properties of the "task2DueDate" datetime field:
dueDatetime.png
dueDatetime.png (27.12 KiB) Viewed 9588 times
Then create another trigger to write the due date for Task2 in the database after finishing Task1:
Code: Select all
if (!empty(@@task2DueDate)) {
   $dueDate = @@task2DueDate;
   $caseId = @@APPLICATION;
   $index = @%INDEX;
   $sql = "SELECT * FROM APP_CACHE_VIEW WHERE APP_UID='$caseId' AND LAST_DEL_INDEX=$index";
   $aNextTask = executeQuery($sql);
   if (empty($aNextTask)) {
      throw new Exception("Unable to find next task in APP_CACHE_VIEW.");
   }
   $nextIndex = $aNextTask[1]['DEL_INDEX'];
   $updateSql = "UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE='$dueDate' 
      WHERE APP_UID='$caseId' AND DEL_INDEX=$nextIndex";
   @@ret = executeQuery($updateSql);
}  
Set this trigger to execute after routing in Task1.

Then, configure ProcessMaker to allow UPDATE statements in PM's core tables (like APP_DELEGATION), by editing the workflow/engine/config/execute-query-blacklist.ini file. Change this line from:
Code: Select all
queries  = "INSERT|UPDATE|REPLACE|DELETE|TRUNCATE"
To:
Code: Select all
queries  = "INSERT|REPLACE|DELETE|TRUNCATE"
#813911
Hi Amos,

Thank you for your reply. I have implemented your suggestion and while I think it works, it is not exactly what I was after:

In Task 1 - the user enters a date - say its task1OriginalDate (that date is taken from some other system) - e.g. 01-Apr-2018

The user executes Step 1 on the same day or some days after task1OriginalDate (e.g. 04-Apr-2018)

When Task 1 is executed (i.e. Submit) and the process moves to Task 2, the user assigned to Task 2 must have a due date which is based on task1OriginalDate + x days and considering the calendar attached to the Task.

Task 2 will therefore be x days from Task 1 (considering any holidays and non-working days based on calendar)

I hope this makes more sense - can the solution you provided be modified to cater for this functionality?

If you take the line:

@@task2DueDate = date("Y-m-d H:i:s", strtotime($task1OriginalDate . ' +10 days ' ));

My understanding is that it just adds 10 days to make task2DueDate 10 days after task1OriginalDate ? Or does it take calendar into account? I was trying to test this today, but my system crashed ...

Any suggestions?

Thanks again
#813925
Install my extraFunctions plugin:
https://github.com/amosbatto/pmcommunity

And then you can use my PMFCalculateDate() function:
Code: Select all
PMFCalculateDate() calculates the date for a specified time duration based 
on the configured calendar for a specified user, task and process. In
ProcessMaker, the calendar of the user has priority. If the user doesn't have
a calendar, then the calendar of the task is used. If the task doesn't have a 
calendar, then the calendar of the process is used. 

PMFCalculateDate($startTime, $duration, $timeUnits = 'DAYS',
   $userUid = null, $taskUid = null, $processUid = null)
   
Parameters:
  string $startTime:  Datetime in "YYYY-MM-DD HH:MM:SS" format from which to start.
  float  $duration:   Number of time units to add to the $startTime.
  string $timeUnits:  The unit of time for the $duration, which can be:
                      'DAYS' (default), 'HOURS' or 'MINUTES'.
  string $userUid:    Unique ID of user assigned to the task. Default is the 
                      current logged-in user.
  string $taskUid:    Unique ID of the task whose duration will be calculated. 
                      Default is the current task.
  string $processUid: Unique ID of the process. Default is the current process.  
  
Return Value:
  A string representing the calculated datetime in "YYYY-MM-DD HH:MM:SS" format.

Example:
Get the date in 10 working days using configured calendar for the current user and task:
---------------
@@date = PMFCalculateDate("2017-04-04 12:30:20", 10, "DAYS"); 
---------------
#814036
Hello Amosbatto.

I can NOT Install the extraFunctions plugin. It says "Plugins Failed to import the file extraFunctions-0.1.tar . It is an invalid file or is not a plugin." I tried is several ways but no luck. Could you let me know how to install Extra Functions please?

Thank you

amosbatto wrote:Install my extraFunctions plugin:
https://github.com/amosbatto/pmcommunity

And then you can use my PMFCalculateDate() function:
Code: Select all
PMFCalculateDate() calculates the date for a specified time duration based 
on the configured calendar for a specified user, task and process. In
ProcessMaker, the calendar of the user has priority. If the user doesn't have
a calendar, then the calendar of the task is used. If the task doesn't have a 
calendar, then the calendar of the process is used. 

PMFCalculateDate($startTime, $duration, $timeUnits = 'DAYS',
   $userUid = null, $taskUid = null, $processUid = null)
   
Parameters:
  string $startTime:  Datetime in "YYYY-MM-DD HH:MM:SS" format from which to start.
  float  $duration:   Number of time units to add to the $startTime.
  string $timeUnits:  The unit of time for the $duration, which can be:
                      'DAYS' (default), 'HOURS' or 'MINUTES'.
  string $userUid:    Unique ID of user assigned to the task. Default is the 
                      current logged-in user.
  string $taskUid:    Unique ID of the task whose duration will be calculated. 
                      Default is the current task.
  string $processUid: Unique ID of the process. Default is the current process.  
  
Return Value:
  A string representing the calculated datetime in "YYYY-MM-DD HH:MM:SS" format.

Example:
Get the date in 10 working days using configured calendar for the current user and task:
---------------
@@date = PMFCalculateDate("2017-04-04 12:30:20", 10, "DAYS"); 
---------------
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]