I have a table with the following data for an example
BNO RNO FromPeriod EndPeriod
=== ===== ========== ==========
01 0123 01/2010 05/2011
02 159 01/2010 01/2010
03 0525 01/2010 01/2010
And I want to throw an error message when the dates overlap for the same BNO and RNO by creating new rows
BNO RNO FromPeriod EndPeriod
=== ===== ========== ==========
01 0123 05/2010 01/2011
and ignore if the dates do not overlap.
BNO RNO FromPeriod EndPeriod
=== ===== ========== ==========
01 0123 05/2009 11/2009
01 0123 05/2015 01/2016
I have tried the following but couldn't achieve the result I am expecting.
function validatePeriodRange(BNO, RNO, FromPeriod, ToPeriod){
for (gridRow = 2; gridRow <= $("tr",$("#GRID_BRP")).length; gridRow++){
var rowBoxNumber= cellValue("BNUM",gridRow)
var rowVatReg= cellValue("RNUM",gridRow)
var rowFrom= cellValue("FROMPERIOD",gridRow)
var rowTo= cellValue("TOPERIOD",gridRow)
rowFrom= 20 +rowFrom.substring(3,5) + rowFrom.substring(0,2)
rowTo= 20 +rowTo.substring(3,5) + rowTo.substring(0,2)
currentFrom = 20 +currentFrom.substring(3,5) + currentFrom.substring(0,2)
currentTo = 20 +currentTo.substring(3,5) + currentTo.substring(0,2)
if(currentBoxNumber == rowBoxNumber && currentVatReg == rowVatReg){
if(currentFrom >= rowFrom && currentFrom<= rowTo){
return 1 // Error message
}
if(currentTo >= rowFrom && currentTo<= rowTo){
return 1
}
if(currentFrom >= rowFrom && rowTo==""){
return 1
}
if(currentTo >= rowFrom && rowTo==""){
return 1
}
}
}
return 0 // No error message
}