Mobile. Take into account the time zones (relevant for 7.6 и v1) of both the server and the mobile app
Symptoms
In the sales outlet card, when populating the "Delivery time from" and "Delivery time to" fields from a tablet, the time is converted to a different time zone during synchronization with a desktop application. For example, if you populate the fields with 17:00 and 18:00 respectively, the desktop app will display the time as 14:00 and 15:00. Moreover, once synchronized, the fields on the mobile app will display 14:00 and 15:00 as well.
Cause
Fixed in version 7.8
Solution
The fix (which avoids transferring any server changes from version 7.8) is provided below:
Step 1
Create the UsrSyncExtension ("Module" type) schema in a custom package.
Step 2
Add the following code to the schema:
var sysAdminUnitStore = Ext.create("Ext.data.Store", {model: "SysAdminUnit"}); sysAdminUnitStore.setProxy("odata"); sysAdminUnitStore.load({ queryConfig: Ext.create("Terrasoft.QueryConfig", { modelName: "SysAdminUnit", autoSetProxy: false, columns: ["TimeZoneId"] }), filters: Ext.create("Terrasoft.Filter", { property: "Contact", value: Terrasoft.CurrentUserInfo.contactId }), callback: function(records, operation, success) { if (success === true && records.length > 0) { var firstRecord = records[0]; var timeZoneCode = firstRecord.get("TimeZoneId"); if (!Ext.isEmpty(timeZoneCode)) { var timeZoneStore = Ext.create("Ext.data.Store", {model: "TimeZone"}); timeZoneStore.setProxy("odata"); timeZoneStore.load({ queryConfig: Ext.create("Terrasoft.QueryConfig", { modelName: "TimeZone", autoSetProxy: false, columns: ["Offset"] }), filters: Ext.create("Terrasoft.Filter", { property: "Code", value: timeZoneCode }), callback: function(timeZoneRecords, timeZoneOperation, timeZoneSuccess) { if (timeZoneSuccess === true && timeZoneRecords.length > 0) { var timeZoneRecord = timeZoneRecords[0]; var offset = timeZoneRecord.get("Offset"); var offsetValue = 0; if (!Ext.isEmpty(offset)) { offset = offset.replace("GMT", ""); if (!Ext.isEmpty(offset)) { var sign = (offset.substring(0, 1) === "-") ? 1 : -1; var hours = parseInt(offset.substr(1, 2)); var minutes = parseInt(offset.substr(4, 2)); offsetValue = sign * (hours * 60 + minutes); } } Terrasoft.Configuration.CurrentUserTimeZoneOffset = offsetValue; } }, scope: this }); } } }, scope: this }); if (!Terrasoft.Configuration.processColumn) { Terrasoft.Configuration.processColumn = Terrasoft.OData.ResponseParser.processColumn; } Terrasoft.OData.ResponseParser.processColumn = function(data, queryConfig, record, columnName) { var model = record.self; var columnConfig = model.ColumnConfigs.get(columnName); var columnValue = data[columnName]; if ((columnConfig.columnType === Terrasoft.ColumnTypes.date || columnConfig.columnType === Terrasoft.ColumnTypes.datetime) && !Ext.isEmpty(Terrasoft.Configuration.CurrentUserTimeZoneOffset)) { if (columnValue.indexOf("/") !== -1) { var timeZoneOffset = Terrasoft.Configuration.CurrentUserTimeZoneOffset; columnValue = new Date(parseInt(columnValue.substr(6))); columnValue = new Date(columnValue.getTime() + timeZoneOffset * 60 * 1000); } else { columnValue = Terrasoft.util.convertISOStringToDate(columnValue); } record.set(columnName, columnValue); } else { Ext.callback(Terrasoft.Configuration.processColumn, Terrasoft.OData.ResponseParser, arguments); } };
Step 3
Add the manifest of the mobile application to the current package (the manifest of the corresponding workplace) and add the UsrSyncExtension schema to it (namely, add it to SyncExtensions and CustomSchemas):
"SyncExtensions": [ "UsrSyncExtension" ], "CustomSchemas": [ "UsrSyncExtension" ],
The code gets the current user's time zone from SysAdminUnit, and uses the received time zone during synchronization and input.