Skip to content
Snippets Groups Projects
Commit 3910bc55 authored by Benjamin Ulrich's avatar Benjamin Ulrich :speech_balloon: Committed by Sebastian Pongratz
Browse files

Sales 1084987 district using database specific functions

parent 75c2cab9
No related branches found
No related tags found
No related merge requests found
import("system.SQLTYPES");
import("Employee_lib");
import("KeywordRegistry_basic");
import("Sql_lib");
......@@ -13,26 +14,33 @@ rawvalue = (rawvalue == "true");
if(operator == "1" && rawvalue || operator == "2" && !rawvalue )
{
operator2 = SqlBuilder.IN();
}
else if(operator == "1" && !rawvalue || operator == "2" && rawvalue)
{
operator2 = SqlBuilder.NOT_IN();
}
else
{
sqlCond = "1=1";
}
if (sqlCond == "")
{
var maskingUtils = new SqlMaskingUtils();
var currentDate = maskingUtils.currentDate();
sqlCond = new SqlBuilder().where("CONTACT.CONTACTID",
newSelect("DISTRICTCONTACT.CONTACT_ID")
.from("DISTRICTCONTACT")
.where("DISTRICTCONTACT.ADVISER_CONTACT_ID", EmployeeUtils.getCurrentContactId())
.and(
newWhere(
newWhere("current_date >= cast(DISTRICTCONTACT.VALID_FROM as DATE)")
.and("current_date <= cast(DISTRICTCONTACT.VALID_UNTIL as DATE)"))
.or(newWhere("current_date >= cast(DISTRICTCONTACT.VALID_FROM as DATE)")
newWhere(currentDate + " >= " + maskingUtils.cast("DISTRICTCONTACT.VALID_FROM", SQLTYPES.DATE))
.and(currentDate + " <= " + maskingUtils.cast("DISTRICTCONTACT.VALID_UNTIL", SQLTYPES.DATE)))
.or(newWhere(currentDate + " >= " + maskingUtils.cast("DISTRICTCONTACT.VALID_FROM", SQLTYPES.DATE))
.and("DISTRICTCONTACT.VALID_UNTIL is null")))
.and("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$active()), operator2).toString();
}
result.string(sqlCond);
\ No newline at end of file
import("system.SQLTYPES");
import("Employee_lib");
import("KeywordRegistry_basic");
import("Sql_lib");
......@@ -11,17 +12,24 @@ var sqlCond = "";
rawvalue = (rawvalue == "true");
if(operator == "1" && rawvalue || operator == "2" && !rawvalue )
{
operator2 = SqlBuilder.IN();
}
else if(operator == "1" && !rawvalue || operator == "2" && rawvalue)
{
operator2 = SqlBuilder.NOT_IN();
}
else
{
sqlCond = "1=1";
}
if (sqlCond == "")
{
var maskingUtils = new SqlMaskingUtils();
var currentDate = maskingUtils.currentDate();
sqlCond = new SqlBuilder().where("CONTACT.CONTACTID",
newSelect("pers.CONTACTID")
.from("DISTRICTCONTACT")
......@@ -30,11 +38,11 @@ if (sqlCond == "")
.where("DISTRICTCONTACT.ADVISER_CONTACT_ID", EmployeeUtils.getCurrentContactId())
.and(
newWhere(
newWhere("current_date >= cast(DISTRICTCONTACT.VALID_FROM as DATE)")
.and("current_date <= cast(DISTRICTCONTACT.VALID_UNTIL as DATE)"))
.or(newWhere("current_date >= cast(DISTRICTCONTACT.VALID_FROM as DATE)")
newWhere(currentDate + " >= " + maskingUtils.cast("DISTRICTCONTACT.VALID_FROM", SQLTYPES.DATE))
.and(currentDate + " <= " + maskingUtils.cast("DISTRICTCONTACT.VALID_UNTIL", SQLTYPES.DATE)))
.or(newWhere(currentDate + " >= " + maskingUtils.cast("DISTRICTCONTACT.VALID_FROM", SQLTYPES.DATE))
.and("DISTRICTCONTACT.VALID_UNTIL is null")))
.and("DISTRICTCONTACT.STATUS", $KeywordRegistry.contactStatus$active()), operator2).toString();
}
result.string(sqlCond);
\ No newline at end of file
......@@ -4,8 +4,9 @@ import("Sql_lib");
import("ActivityTask_lib");
var maskingUtils = new SqlMaskingUtils();
var currentDate = maskingUtils.currentDate();
var dateDiff = maskingUtils.dayDateDifference(
"current_date",
currentDate,
SqlUtils.nullableWithDefault(
ActivityUtils.getLastActivityDateSql("SALESPROJECT.SALESPROJECTID"),
"SALESPROJECT.DATE_NEW"
......
......@@ -4119,6 +4119,28 @@ SqlMaskingUtils.prototype.makeDate = function(pYear, pMonth, pDay)
}
}
/**
* Returns the database equivalent of the current date function as String depending on the database type
*
*/
SqlMaskingUtils.prototype.currentDate = function()
{
switch(this.dbType)
{
case db.DBTYPE_POSTGRESQL8:
case db.DBTYPE_ORACLE10_CLUSTER:
case db.DBTYPE_ORACLE10_THIN:
case db.DBTYPE_ORACLE10_OCI:
case db.DBTYPE_MARIADB10:
case db.DBTYPE_DERBY10:
return "current_date";
case db.DBTYPE_MYSQL4:
return "current_date()";
case db.DBTYPE_SQLSERVER2000:
return "getdate()";
}
}
/**
* functions for various Sql-actions
* Do not create an instance of this!
......@@ -4799,3 +4821,4 @@ SqlUtils.nullableWithDefault = function(pNullableExpr, pDefaultExpr)
.when("(" + pNullableExpr.toString() + ") is null").then(pDefaultExpr)
.elseValue(pNullableExpr);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment