diff --git a/process/Offer_lib/process.js b/process/Offer_lib/process.js index 72439ab6561f3560a64226df4ca40cb40daa881e..9c54aa258e3bc90f127e995c3b264db24dc838ff 100644 --- a/process/Offer_lib/process.js +++ b/process/Offer_lib/process.js @@ -130,6 +130,9 @@ OfferUtils.buildOfferReport = function (pOfferID) .where("OFFER.OFFERID", pOfferID) .arrayRow(); + if (offerData.length === 0) + return null; + var letterSalutation = offerData[15]; var language = newSelect("ISO2") diff --git a/process/Sql_lib/documentation.adoc b/process/Sql_lib/documentation.adoc index b654ff1cf321ff9aa3c11e5d623546b6035facf5..6bf24551ca16887e04b4463d8f61f1ad7deba94d 100644 --- a/process/Sql_lib/documentation.adoc +++ b/process/Sql_lib/documentation.adoc @@ -472,7 +472,7 @@ If you want to check also for `!= ""` and `vars.exists(...)`, you have to do it === other condition than "# = ?" If you need something different from the default "# = ?" condition just pass a string to pCondition. -Note that # is replaced by the column of the table in the first parameter and ? is the place in which the value is to be inserted. +Note that # is replaced by the column of the table in the first parameter and ? is the place in which the value is to be inserted. For many conditions there are already SqlBuilder constants that can be used (e. g. SqlBuilder.NOT_EQUAL(), SqlBuilder.GREATER()). === condition like "year(#) = ?" with specific FieldType diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index 109db23f3764311a6a12dcd07a97378636198273..99770a39bc0040c3aec3f71c32e90ac058e67ab8 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -1413,6 +1413,18 @@ SqlBuilder.prototype._whereSubquery = function(pSubquery, pMandatory, pCondition */ SqlBuilder.prototype._addWhere = function(pFieldOrCond, pValue, pMandatory, pCondition, pFieldType, pAddPreparedConditionCallback) { + //In a special case, pCondition can be a function. It will be called with the alias as argument and + //must return an array of the condition string and (optionally) the required sql field type. + if (pCondition && typeof pCondition === "function") + { + var resCond = pCondition(this.alias); + if (Array.isArray(resCond)) + { + pCondition = resCond[0]; + pFieldType = pFieldType || resCond[1]; + } + } + if (pCondition && !SqlUtils.checkConditionFormat(pCondition)) throw SqlBuilder._ERROR_CONDITION_WRONG_FORMAT(); @@ -1666,7 +1678,7 @@ SqlBuilder.IN = function() * @return {String} * * @example - * var cond = newWhere("PERSON.FIRSTNAME", "Fritz", SqlBuilder.EXISTS()) + * var cond = newWhere(null, mySubSqlBuilder, SqlBuilder.EXISTS()) */ SqlBuilder.EXISTS = function() { @@ -1679,7 +1691,7 @@ SqlBuilder.EXISTS = function() * @return {String} * * @example - * var cond = newWhere("PERSON.FIRSTNAME", "Fritz", SqlBuilder.NOT_EXISTS()) + * var cond = newWhere(null, mySubSqlBuilder, SqlBuilder.NOT_EXISTS()) */ SqlBuilder.NOT_EXISTS = function() { @@ -1688,16 +1700,17 @@ SqlBuilder.NOT_EXISTS = function() /** * Constant-like function which provides a value for pCondition if you need a "year(#) = ?" statement. - * Make sure you use SQLTYPES.INTEGER as type. + * If you use this, the default pFieldType will be SQLTYPES.INTEGER. * - * @return {String} + * @return {Function} * * @example - * var cond = newWhere("FORECAST.DATE_START", DateUtils.getCurrentYear(), SqlBuilder.YEAR_EQUALS(), SQLTYPES.INTEGER) + * var cond = newWhere("FORECAST.DATE_START", DateUtils.getCurrentYear(), SqlBuilder.YEAR_EQUALS()); */ SqlBuilder.YEAR_EQUALS = function () { - return (new SqlMaskingUtils().yearFromDate("#")) + " = ?"; + //function will be called later so it can use the alias of the SqlBuilder + return function (pAlias) {return [(new SqlMaskingUtils(pAlias).yearFromDate("#")) + " = ?", SQLTYPES.INTEGER];}; } /** @@ -1793,6 +1806,66 @@ SqlBuilder.LESS_OR_EQUAL = function () return "# <= ?"; } +/** + * Object providing constant-like functions for sql-any-conditions. + */ +SqlBuilder.ANY = { + /** + * Constant-like function that returns a "# = any ?" statement. + */ + EQUAL : function () {return "# = any ?";}, + /** + * Constant-like function that returns a "# <> any ?" statement. + */ + NOT_EQUAL : function () {return "# <> any ?";}, + /** + * Constant-like function that returns a "# > any ?" statement. + */ + GREATER : function () {return "# > any ?";}, + /** + * Constant-like function that returns a "# >= any ?" statement. + */ + GREATER_OR_EQUAL : function () {return "# >= any ?";}, + /** + * Constant-like function that returns a "# < any ?" statement. + */ + LESS : function () {return "# < any ?";}, + /** + * Constant-like function that returns a "# <= any ?" statement. + */ + LESS_OR_EQUAL : function () {return "# <= any ?";} +} + +/** + * Object providing constant-like functions for sql-all-conditions. + */ +SqlBuilder.ALL = { + /** + * Constant-like function that returns a "# = all ?" statement. + */ + EQUAL : function () {return "# = all ?";}, + /** + * Constant-like function that returns a "# <> all ?" statement. + */ + NOT_EQUAL : function () {return "# <> all ?";}, + /** + * Constant-like function that returns a "# > all ?" statement. + */ + GREATER : function () {return "# > all ?";}, + /** + * Constant-like function that returns a "# >= all ?" statement. + */ + GREATER_OR_EQUAL : function () {return "# >= all ?";}, + /** + * Constant-like function that returns a "# < all ?" statement. + */ + LESS : function () {return "# < all ?";}, + /** + * Constant-like function that returns a "# <= all ?" statement. + */ + LESS_OR_EQUAL : function () {return "# <= all ?";} +} + /** * Throws an error if pValue is null, undefined or a SqlBuilder without condition (or if pValue is a $-variable: error if the result of it is null or undefined)<br/> * Also throws an error if pFieldOrCond is the only parameter and it is null<br/>