dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
140 lines • 5.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentSeriesService = void 0;
const tslib_1 = require("tslib");
const livelink_query_service_1 = require("../lib-core/livelink-query-service");
const livelink_query_apparea_1 = require("../lib-core/livelink/livelink-query-apparea");
const dms_root_container_1 = require("../ioc/dms-root-container");
const dms_platform_bridge_factory_1 = require("../platform/dms-platform-bridge-factory");
const app_service_app_1 = require("./app-service-app");
const application_context_service_1 = require("./application-context-service");
const tools_1 = require("./tools");
class DocumentSeriesService extends app_service_app_1.CoreAppService {
constructor(dms) {
super(dms, null);
this.series = [];
this.series = [];
}
composeFullSerieNo(value, mask) {
var s = tools_1.Tools.formatString(mask, value);
return s;
}
initializeSerie(documentType, current, max, mask) {
var serie = this.findSerie(documentType);
if (!serie) {
serie = {
documentType: documentType,
current: current,
max: current,
mask: mask,
};
this.series.push(serie);
}
return serie;
}
load() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (this.series.length == 0) {
var s = yield (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("retreiveDocSeries", undefined);
if (s && typeof (s) == "string")
this.series = JSON.parse(s);
else
this.series = [];
}
});
}
save() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (0, dms_platform_bridge_factory_1.PlatformBridgeFactory)(this.dms).execute("saveAllDocSeries", { series: JSON.stringify(this.series) });
});
}
findSerie(documentType) {
for (var i = 0; i < this.series.length; i++) {
if (this.series[i].documentType == documentType) {
return this.series[i];
}
}
return null;
}
getCurrentNumber(documentType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.load();
var serie = this.findSerie(documentType);
if (!serie) {
serie = this.initializeSerie(documentType, 0, 999999, '{0}');
}
return this.composeFullSerieNo(serie.current, serie.mask);
});
}
getNextNumber(documentType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.load();
var serie = this.findSerie(documentType);
if (!serie) {
serie = this.initializeSerie(documentType, 0, 999999, '{0}');
}
var v = serie.current + 1;
return this.composeFullSerieNo(v, serie.mask);
});
}
incrementNumber(documentType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.load();
var serie = this.findSerie(documentType);
if (!serie) {
serie = this.initializeSerie(documentType, 0, 999999, '{0}');
}
serie.current++;
yield this.save();
const appCode = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService).appCode;
const packet = {
appName: appCode,
tableName: 'DocumentSerieUpdate',
boName: 'DocumentSerieUpdate',
objectTableName: 'DocumentSerieUpdate',
documentType: documentType,
current: serie.current,
sync: false,
onDate: new Date()
};
const dms = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService);
const q = new livelink_query_apparea_1.LiveLinkQueryAppArea(dms, livelink_query_service_1.appAreaServiceName, 'MOBFL', 'MobileDocumentSerie', 'MOBFL_MobileDocumenSerie', null, [], null, false);
yield q.postToSyncLog(packet);
return this.composeFullSerieNo(serie.current, serie.mask);
});
}
synchronize(userName) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const dms = dms_root_container_1.RootDIContainer.inject(application_context_service_1.DmsApplicationService);
const q = new livelink_query_apparea_1.LiveLinkQueryAppArea(dms, livelink_query_service_1.appAreaServiceName, 'MOBFL', 'MobileDocumentSerie', 'MOBFL_MobileDocumenSerie', null, [], null, false);
yield this.load();
if (this.series.length == 0) {
q.filter(`userName eq '${userName}'`);
}
else {
q.filter(`userName eq '${userName}' and sync eq true`);
}
const remoteSeries = yield q.executeSelect();
remoteSeries.forEach(s => {
const localSerie = this.findSerie(s.documentType);
if (localSerie) {
localSerie.current = s.value;
localSerie.mask = s.mask;
localSerie.max = s.endValue;
}
else {
const newSerie = {
documentType: s.documentType,
current: s.value,
mask: s.mask,
max: s.endValue
};
this.series.push(newSerie);
}
});
yield this.save();
});
}
}
exports.DocumentSeriesService = DocumentSeriesService;
//# sourceMappingURL=docseries-service.js.map