Share ideas, ask questions, and get feedback about developing for ProcessMaker

Moderator: amosbatto

Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
By omermahgoub
#19318
Hello Everyone,

I face a problem when I created a field in a dynaform (Date Field) I found that the most day i can access is (15 - February -2014)! how can i jump to date beyond that.

One more this, I want to create my own field in a dynaform called hijri calendar, It's Islamic calendar base on moon duration and it differ from the default calendar, well I found some code for that: http://www.al-habib.info/islamic-calend ... artext.htm
How can i create my own field in the dynaform?
what is the related files i need to modify? please help
User avatar
By amosbatto
#19324
omermahgoub wrote:I face a problem when I created a field in a dynaform (Date Field) I found that the most day i can access is (15 - February -2014)! how can i jump to date beyond that.
You need to change the Relative End Date property for the date field (or End Date property if you are using static dates). See: http://wiki.processmaker.com/index.php/2.0/Dates
omermahgoub wrote:One more this, I want to create my own field in a dynaform called hijri calendar, It's Islamic calendar base on moon duration and it differ from the default calendar, well I found some code for that: http://www.al-habib.info/islamic-calend ... artext.htm
How can i create my own field in the dynaform?
This took me a while to figure out, because that script has no comments to explain what it is doing, so it was hard to modify.

In your DynaForm, create a date field named "selectDate" for the user to select a date and a read-only textbox field named "showHijriDate" to display the Hijri date. Then create a javascript object in the DynaForm and add the following code:
Code: Select all
function gmod(n,m){
  return ((n%m)+m)%m;
}

/*
Parameters:
string dateToConvert: Date string in the format "YYYY-MM-DD"
int adjustDays: The number of days to adjust the date. It can be a negative or positive integer.
*/
function kuwaitiCalendar(dateToConvert, adjustDays){
  var today = new Date(dateToConvert);
  if (adjustDays) {
    adjustmili = 1000 * 60 * 60 * 24 * adjustDays;
    todaymili = today.getTime() + adjustmili;
    today = new Date(todaymili);
  }
  day = today.getDate();
  month = today.getMonth();
  year = today.getFullYear();
  m = month + 1;
  y = year;
  if (m < 3) {
    y -= 1;
    m += 12;
  }

  a = Math.floor(y / 100.0);
  b = 2 - a + Math.floor( a / 4.0);
  if (y < 1583) b = 0;
  if (y == 1582) {
    if (m > 10) b = -10;
    if (m == 10) {
      b = 0;
      if (day > 4) b = -10;
    }
  }

  jd = Math.floor(365.25*(y+4716))+Math.floor(30.6001*(m+1))+day+b-1524;

  b = 0;
  if (jd > 2299160) {
    a = Math.floor((jd-1867216.25)/36524.25);
    b = 1+a-Math.floor(a/4.);
  }
  bb = jd+b+1524;
  cc = Math.floor((bb - 122.1) / 365.25);
  dd = Math.floor(365.25 * cc);
  ee = Math.floor((bb-dd) / 30.6001);
  day = (bb - dd) - Math.floor(30.6001 * ee);
  month = ee - 1;
  if(ee>13) {
    cc += 1;
    month = ee - 13;
  }
  year = cc - 4716;

  if(adjustDays) {
    wd = gmod(jd + 1 - adjustDays, 7) + 1;
  } else {
    wd = gmod(jd + 1, 7) + 1;
  }

  iyear = 10631.0 / 30.0;
  epochastro = 1948084;
  epochcivil = 1948085;

  shift1 = 8.01 / 60.0;
  
  z = jd-epochastro;
  cyc = Math.floor(z / 10631.);
  z = z - 10631 * cyc;
  j = Math.floor((z - shift1) / iyear);
  iy = 30 * cyc + j;
  z = z - Math.floor(j * iyear + shift1);
  im = Math.floor((z + 28.5001) / 29.5);
  if (im == 13)
       im = 12;
  id = z - Math.floor(29.5001 * im - 29);

  var myRes = new Array(8);

  myRes[0] = day; //calculated day (CE)
  myRes[1] = month - 1; //calculated month (CE)
  myRes[2] = year; //calculated year (CE)
  myRes[3] = jd - 1; //julian day number
  myRes[4] = wd - 1; //weekday number
  myRes[5] = id; //islamic date
  myRes[6] = im - 1; //islamic month
  myRes[7] = iy; //islamic year

  return myRes;
}

/*
Parameters:
string dateToConvert: Date string in the format "YYYY-MM-DD"
int adjustDays: The number of days to adjust the date. It can be a negative or positive integer.
*/
function writeIslamicDate(dateToConvert, adjustDays) {
  var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt");
  var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
     "Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban",
     "Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja");
  var iDate = kuwaitiCalendar(dateToConvert, adjustDays);
  var outputIslamicDate = wdNames[iDate[4]] + ", " + iDate[5] + " " +
       iMonthNames[iDate[6]] + " " + iDate[7] + " AH";
  return outputIslamicDate;
}

function setHajriDate() {
   getField('showHajriDate').value = writeIslamicDate(this.value, 0);
}

getField('selectDate').onchange = setHajriDate;
You may have to adjust the days for your country, since there is no standard Islamic date. To move the date forward one day, change this line:
Code: Select all
   getField('showHajriDate').value = writeIslamicDate(this.value, 1);
to move the date backward one day:
Code: Select all
   getField('showHajriDate').value = writeIslamicDate(this.value, -1);
By omermahgoub
#19333
Thankx for the reply amos
omermahgoub wrote:I face a problem when I created a field in a dynaform (Date Field) I found that the most day i can access is (15 - February -2014)! how can i jump to date beyond that.
You need to change the Relative End Date property for the date field (or End Date property if you are using static dates). See: http://wiki.processmaker.com/index.php/2.0/Dates
I tried this solution many times, for different values, but still i get the same date (15 - February -2014)!, I think it count about two year from the i at. can you please give me an example for the Start Relative Date and End Relative Date if i want the most access date as 2050.
omermahgoub wrote:One more this, I want to create my own field in a dynaform called hijri calendar, It's Islamic calendar base on moon duration and it differ from the default calendar, well I found some code for that: http://www.al-habib.info/islamic-calend ... artext.htm
How can i create my own field in the dynaform?
This took me a while to figure out, because that script has no comments to explain what it is doing, so it was hard to modify.
Yes, its equation to calculate the date to it's hijri approximate date. I asked if i want the user to read the date (from the calender date) as hijri.
In your DynaForm, create a date field named "selectDate" for the user to select a date and a read-only textbox field named "showHijriDate" to display the Hijri date. Then create a javascript object in the DynaForm and add the following code:
I read this many times, I did get it, can you please enplane it in a different way!

Regards,
OMER
User avatar
By amosbatto
#19344
omermahgoub wrote:I tried this solution many times, for different values, but still i get the same date (15 - February -2014)!, I think it count about two year from the i at. can you please give me an example for the Start Relative Date and End Relative Date if i want the most access date as 2050.
Set Relative End Date: +40y
That will give you dates until year 2052.
omermahgoub wrote:I read this many times, I did get it, can you please enplane it in a different way!
Paste this XML code in your DynaForm and it should work:
Code: Select all
<selectDate type="date" relativedate="1" beforedate="0m" afterdate="8y" mask="%Y-%m-%d" editable="0" required="0" readonly="0" showtime="0" defaultvalue_sel="empty" mode="edit" btn_cancel="Cancel" startdate="" enddate="" defaultvalue="" hint="" savelabel="0">
    <en>Select Date</en>
  </selectDate>
  <showHajriDate type="text" maxlength="64" validate="Any" required="0" readonly="0" size="30" mode="edit" btn_cancel="Cancel">
    <en>Hajri Date</en>
  </showHajriDate>
  <mycode type="javascript"><![CDATA[function gmod(n,m){
  return ((n%m)+m)%m;
}

/*
Parameters:
string dateToConvert: Date string in the format "YYYY-MM-DD"
int adjustDays: The number of days to adjust the date. It can be a negative or positive integer.
*/
function kuwaitiCalendar(dateToConvert, adjustDays){
  var today = new Date(dateToConvert);
  if (adjustDays) {
    adjustmili = 1000 * 60 * 60 * 24 * adjustDays;
    todaymili = today.getTime() + adjustmili;
    today = new Date(todaymili);
  }
  day = today.getDate();
  month = today.getMonth();
  year = today.getFullYear();
  m = month + 1;
  y = year;
  if (m < 3) {
    y -= 1;
    m += 12;
  }

  a = Math.floor(y / 100.0);
  b = 2 - a + Math.floor( a / 4.0);
  if (y < 1583) b = 0;
  if (y == 1582) {
    if (m > 10) b = -10;
    if (m == 10) {
      b = 0;
      if (day > 4) b = -10;
    }
  }

  jd = Math.floor(365.25*(y+4716))+Math.floor(30.6001*(m+1))+day+b-1524;

  b = 0;
  if (jd > 2299160) {
    a = Math.floor((jd-1867216.25)/36524.25);
    b = 1+a-Math.floor(a/4.);
  }
  bb = jd+b+1524;
  cc = Math.floor((bb - 122.1) / 365.25);
  dd = Math.floor(365.25 * cc);
  ee = Math.floor((bb-dd) / 30.6001);
  day = (bb - dd) - Math.floor(30.6001 * ee);
  month = ee - 1;
  if(ee>13) {
    cc += 1;
    month = ee - 13;
  }
  year = cc - 4716;

  if(adjustDays) {
    wd = gmod(jd + 1 - adjustDays, 7) + 1;
  } else {
    wd = gmod(jd + 1, 7) + 1;
  }

  iyear = 10631.0 / 30.0;
  epochastro = 1948084;
  epochcivil = 1948085;

  shift1 = 8.01 / 60.0;
  
  z = jd-epochastro;
  cyc = Math.floor(z / 10631.);
  z = z - 10631 * cyc;
  j = Math.floor((z - shift1) / iyear);
  iy = 30 * cyc + j;
  z = z - Math.floor(j * iyear + shift1);
  im = Math.floor((z + 28.5001) / 29.5);
  if (im == 13)
       im = 12;
  id = z - Math.floor(29.5001 * im - 29);

  var myRes = new Array(8);

  myRes[0] = day; //calculated day (CE)
  myRes[1] = month - 1; //calculated month (CE)
  myRes[2] = year; //calculated year (CE)
  myRes[3] = jd - 1; //julian day number
  myRes[4] = wd - 1; //weekday number
  myRes[5] = id; //islamic date
  myRes[6] = im - 1; //islamic month
  myRes[7] = iy; //islamic year

  return myRes;
}

/*
Parameters:
string dateToConvert: Date string in the format "YYYY-MM-DD"
int adjustDays: The number of days to adjust the date. It can be a negative or positive integer.
*/
function writeIslamicDate(dateToConvert, adjustDays) {
  var wdNames = new Array("Ahad","Ithnin","Thulatha","Arbaa","Khams","Jumuah","Sabt");
  var iMonthNames = new Array("Muharram","Safar","Rabi'ul Awwal","Rabi'ul Akhir",
     "Jumadal Ula","Jumadal Akhira","Rajab","Sha'ban",
     "Ramadan","Shawwal","Dhul Qa'ada","Dhul Hijja");
  var iDate = kuwaitiCalendar(dateToConvert, adjustDays);
  var outputIslamicDate = wdNames[iDate[4]] + ", " + iDate[5] + " " +
       iMonthNames[iDate[6]] + " " + iDate[7] + " AH";
  return outputIslamicDate;
}

function setHajriDate() {
   getField('showHajriDate').value = writeIslamicDate(this.value, 0);
}

getField('selectDate').onchange = setHajriDate;]]></mycode>
Cannot upload CSV

Hi, I am using a multi-file upload. When I upload[…]

A Beginner's Guide for ProcessMaker

I recently completed a book on ProcessMaker - &q[…]

Hi guys. I am a newbie. I don't know how to upgrad[…]

HI Thanks so much! This is just what I need.