Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By Leenomeedo
#814799
Hi;
I am new in processmaker I wanna to add given days to date ; for example in leave request user chose starting date from calender and then type for example 30 days for number of days request how can calculate this days to be added to calender to be automatic display the end of the leave date.
Last edited by Leenomeedo on Fri Jun 22, 2018 6:22 pm, edited 3 times in total.
User avatar
By amosbatto
#814801
If you want to do this in a trigger with PHP:
Code: Select all
@@endDate = date("Y-m-d", strtotime(@@startDate, @%daysToAdd));
Where "startDate" is the variable associated with a datetime field and "daysToAdd" is the variable associated with a text field in a previous DynaForm and "endDate" is the variable associated with a datetime in a future DynaFom.

If you want to do this with JavaScript in a DynaForm, then you can use the following code:
Code: Select all
function calculateEndDate(startDate, daysToAdd) {
  if (startDate == '' || daysToAdd == '' || parseFloat(daysToAdd) == NaN) {
    $("#endDate").setValue('');
  }
  
  var end = moment(startDate).add(daysToAdd, 'days').format("YYYY-MM-DD");
  $("#endDate").setValue(end);
}

$("#startDate").setOnchange(function(newDate, oldDate) {
  calculateEndDate( newDate, $("#daysToAdd").getValue() );
})[attachment=0]add days to date.json[/attachment]

$("#daysToAdd").setOnchange(function(newDays, oldDays) {
  calculateEndDate( $("#startDate").getValue(), newDays );
})
Where "startDate" and "endDate" are the IDs of datetime fields and "daysToAdd" is a text field. To see an example of this code, import the following DynaForm:
(4.59 KiB) Downloaded 312 times
By Leenomeedo
#814819
Ok excuse me so if I follow the way of php trigger where exactly run this trigger to calculate this filed I want to implement this issue before I submit the form and exactly after typing the days to add
amosbatto wrote: Mon Jun 18, 2018 8:48 pm If you want to do this in a trigger with PHP:
Code: Select all
@@endDate = date("Y-m-d", strtotime(@@startDate, @%daysToAdd));
Where "startDate" is the variable associated with a datetime field and "daysToAdd" is the variable associated with a text field in a previous DynaForm and "endDate" is the variable associated with a datetime in a future DynaFom.

If you want to do this with JavaScript in a DynaForm, then you can use the following code:
Code: Select all
function calculateEndDate(startDate, daysToAdd) {
  if (startDate == '' || daysToAdd == '' || parseFloat(daysToAdd) == NaN) {
    $("#endDate").setValue('');
  }
  
  var end = moment(startDate).add(daysToAdd, 'days').format("YYYY-MM-DD");
  $("#endDate").setValue(end);
}

$("#startDate").setOnchange(function(newDate, oldDate) {
  calculateEndDate( newDate, $("#daysToAdd").getValue() );
})add days to date.json

$("#daysToAdd").setOnchange(function(newDays, oldDays) {
  calculateEndDate( $("#startDate").getValue(), newDays );
})
Where "startDate" and "endDate" are the IDs of datetime fields and "daysToAdd" is a text field. To see an example of this code, import the following DynaForm:
add days to date.json
By Leenomeedo
#814825
Sorry for interruption but its not working via php trigger while its working via java script will you kindly please help me to run the trigger via php?
amosbatto wrote: Mon Jun 18, 2018 8:48 pm If you want to do this in a trigger with PHP:
Code: Select all
@@endDate = date("Y-m-d", strtotime(@@startDate, @%daysToAdd));
Where "startDate" is the variable associated with a datetime field and "daysToAdd" is the variable associated with a text field in a previous DynaForm and "endDate" is the variable associated with a datetime in a future DynaFom.

If you want to do this with JavaScript in a DynaForm, then you can use the following code:
Code: Select all
function calculateEndDate(startDate, daysToAdd) {
  if (startDate == '' || daysToAdd == '' || parseFloat(daysToAdd) == NaN) {
    $("#endDate").setValue('');
  }
  
  var end = moment(startDate).add(daysToAdd, 'days').format("YYYY-MM-DD");
  $("#endDate").setValue(end);
}

$("#startDate").setOnchange(function(newDate, oldDate) {
  calculateEndDate( newDate, $("#daysToAdd").getValue() );
})add days to date.json

$("#daysToAdd").setOnchange(function(newDays, oldDays) {
  calculateEndDate( $("#startDate").getValue(), newDays );
})
Where "startDate" and "endDate" are the IDs of datetime fields and "daysToAdd" is a text field. To see an example of this code, import the following DynaForm:
add days to date.json
User avatar
By amosbatto
#814834
Oh sorry, I see that the PHP code I gave you doesn't work. Try this:
Code: Select all
if (!empty(@@startDate)) {
   $sDate = @@startDate.' +'.@%numberDaysToAdd.' days';
   @@endDate = date("Y-m-d", strtotime($sDate));
}
Here is a sample process to try it:
(29.67 KiB) Downloaded 269 times
By Leenomeedo
#814843
Hi
Thank You for your help and support I attached process the case what i want just its simple sample form of leave request content of number of days request,date of starting leave,last date before starting leave (requested date-1) , end Of leave(date of starting leave+number of days) and last filed is return back from leave (end of leave + 1).
Will you please in the same form guide me to add trigger in php to proceed the result before submit
Thank you
Attachments
(37.13 KiB) Downloaded 282 times
User avatar
By amosbatto
#814855
Leenomeedo wrote:Thank You for your help and support I attached process the case what i want just its simple sample form of leave request content of number of days request,date of starting leave,last date before starting leave (requested date-1) , end Of leave(date of starting leave+number of days) and last filed is return back from leave (end of leave + 1).
Sorry, but I don't understand this sentence. Can you make it clearer what you want?
By Leenomeedo
#814860
Thank you for your reply i wish this time I am clear find below the demonstration of my requirements:
The Form content of 5 fields as bellow:-

1- Number of leave days request (This field fill by the user manually example 10 )
2- Staring date of leave (This filed let user to select from calender the first day of leave example 10/06/2018)
3- last working day ( This filed represent the date of last working days calculated by step 2 - (1 day) to be calculated as 09/06/2018).
4- The day of end of leave ( this filed represent last date in leave calculated by step 2 + step 1 it will be appear 19/06/2018)
5- Return back to office (this filed represent as date of return day calculated by step 4 + (1 day ) to be appear 20/06/2018
* Kindly download attachment in my previous post
Please accept my appreciation

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]