var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var FMain;
(function (FMain) {
    var BaseEditor = (function (_super) {
        __extends(BaseEditor, _super);
        function BaseEditor(id, _document) {
            var _this = _super.call(this, EditorProObjectTypes.Editor, id) || this;
            _this._document = _document;
            _this._mode = null;
            _this._systemEditor = null;
            return _this;
        }
        Object.defineProperty(BaseEditor.prototype, "SystemEditor", {
            get: function () {
                if (this._systemEditor == null) {
                    this._systemEditor = this._document.Editors.getValue(this.Id);
                }
                return this._systemEditor;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseEditor.prototype, "Sheets", {
            get: function () {
                return this.SystemEditor.Sheets;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseEditor.prototype, "Document", {
            get: function () {
                return this._document;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseEditor.prototype, "Mode", {
            get: function () {
                return this._mode == null ? +this.SystemEditor.Mode : this._mode;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BaseEditor.prototype, "IsPreviewMode", {
            get: function () {
                return this._mode === EditorShowMode.Preview;
            },
            enumerable: true,
            configurable: true
        });
        BaseEditor.prototype.ResetMode = function () {
            this._mode = null;
        };
        BaseEditor.prototype.CommonGetIsReadonlyEventHandler = function (sheetId, tableId, fieldId, isReadonly) {
            if (this.IsPreviewMode) {
                return true;
            }
            else {
                return isReadonly;
            }
        };
        BaseEditor.prototype.CommonGetIsVisibleEventHandler = function (sheetId, tableId, fieldId, isVisible) {
            if (this.IsPreviewMode) {
                return true;
            }
            else {
                return isVisible;
            }
        };
        BaseEditor.prototype.CommonGetButtonVisible = function (tableId, fieldId, buttonId, isVisible) {
            switch (this.Mode) {
                case EditorShowMode.Preview:
                    return buttonId.indexOf("PreviewButton") > -1;
                default:
                    return isVisible;
            }
        };
        BaseEditor.prototype.GetMainButtonVisible = function (tableId, fieldId, buttonId, isVisible) {
            switch (buttonId) {
                case ClientButton.EditorOkButton.Id:
                    return !this.IsPreviewMode;
                default:
                    return true;
            }
        };
        BaseEditor.prototype.GetMainButtonCaption = function (tableId, fieldId, buttonId, caption) {
            switch (buttonId) {
                case ClientButton.EditorCancelButton.Id:
                    return this.IsPreviewMode ? "OK" : ClientButton.EditorCancelButton.DefaultCaption;
                default:
                    return caption;
            }
        };
        BaseEditor.prototype.Show = function (mode) {
            this._mode = mode;
            var result;
            switch (mode) {
                case EditorShowMode.Create:
                    result = this.SystemEditor.Show(EditorMode.Create);
                    break;
                case EditorShowMode.Edit:
                    result = this.SystemEditor.Show(EditorMode.Edit);
                    break;
                default:
                    result = this.SystemEditor.Show();
            }
            this.ResetMode();
            return result;
        };
        return BaseEditor;
    }(BaseObject));
    FMain.BaseEditor = BaseEditor;
    var BaseOutlayVersionsEditor = (function (_super) {
        __extends(BaseOutlayVersionsEditor, _super);
        function BaseOutlayVersionsEditor(id, document, _sourceTable) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = _sourceTable;
            return _this;
        }
        Object.defineProperty(BaseOutlayVersionsEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        BaseOutlayVersionsEditor.prototype.IsApproved = function () {
            return this._sourceTable.Status === OutlayStatuses.Approved;
        };
        BaseOutlayVersionsEditor.prototype.IsAgreed = function () {
            return this._sourceTable.Status === OutlayStatuses.Agreed;
        };
        BaseOutlayVersionsEditor.prototype.FilterStatuses = function () {
            var status = ObasTableCollection.OutlayStatusSprTable.Status;
            switch (this._sourceTable.Status) {
                case OutlayStatuses.Draft:
                    return (status === OutlayStatuses.Draft ||
                        status === OutlayStatuses.AgreeSubmit);
                case OutlayStatuses.AgreeSubmit:
                    return (status === OutlayStatuses.Draft ||
                        status === OutlayStatuses.AgreeSubmit ||
                        status === OutlayStatuses.Agreed);
                case OutlayStatuses.Agreed:
                    return (status === OutlayStatuses.AgreeSubmit ||
                        status === OutlayStatuses.Agreed ||
                        status === OutlayStatuses.ApproveSubmit);
                case OutlayStatuses.ApproveSubmit:
                    return (status === OutlayStatuses.Agreed ||
                        status === OutlayStatuses.ApproveSubmit ||
                        status === OutlayStatuses.Approved);
                default:
                    return true;
            }
        };
        BaseOutlayVersionsEditor.prototype.CloseEventHandler = function (isSuccess) {
            if (isSuccess) {
                switch (this._sourceTable.Status) {
                    case OutlayStatuses.Approved:
                        this._sourceTable.ApproveVersion();
                        break;
                }
            }
        };
        return BaseOutlayVersionsEditor;
    }(BaseEditor));
    FMain.BaseOutlayVersionsEditor = BaseOutlayVersionsEditor;
    var SumOutlayVersionsEditor = (function (_super) {
        __extends(SumOutlayVersionsEditor, _super);
        function SumOutlayVersionsEditor() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        return SumOutlayVersionsEditor;
    }(BaseOutlayVersionsEditor));
    FMain.SumOutlayVersionsEditor = SumOutlayVersionsEditor;
    var OutlayVersionsEditor = (function (_super) {
        __extends(OutlayVersionsEditor, _super);
        function OutlayVersionsEditor() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this._canLockOutlay = false;
            _this._canUnLockOutlay = false;
            _this._isResultOk = false;
            return _this;
        }
        OutlayVersionsEditor.prototype.EditFieldEventHandler = function (sheetId, fieldId, newValue, oldValue) {
            switch (fieldId) {
                case this.SourceTable.StatusSprField.ForeignKey.Id:
                    this.EditStatusEventHandler(newValue, oldValue);
                    break;
            }
            return true;
        };
        OutlayVersionsEditor.prototype.EditStatusEventHandler = function (newValue, oldValue) {
            if (oldValue === OutlayStatuses.Draft && newValue === OutlayStatuses.AgreeSubmit) {
                if (this.SourceTable.HasFullData() || Client.ShowMessage("Внимание", "Распределены не все доведенные ЛБО. Отправить на согласование?", MessageIcons.Warning, MessageButtons.YesNo) === MessageResults.Yes) {
                    this._canLockOutlay = true;
                }
                else {
                    this.SourceTable.Status = oldValue;
                }
            }
            if (oldValue > OutlayStatuses.Draft && newValue === OutlayStatuses.Draft) {
                this._canUnLockOutlay = true;
            }
        };
        OutlayVersionsEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            this._isResultOk = (buttonResult === MessageResults.Ok);
            return true;
        };
        OutlayVersionsEditor.prototype.CloseEventHandler = function (isSuccess) {
            var _this = this;
            if (isSuccess && this._isResultOk) {
                switch (this.SourceTable.Status) {
                    case OutlayStatuses.Approved:
                        ObasHelper.DoLongOperation(function () {
                            _this.SourceTable.ApproveVersion();
                        });
                        break;
                    case OutlayStatuses.AgreeSubmit:
                        this.LockOutlay(this._canLockOutlay, true);
                        break;
                    case OutlayStatuses.Draft:
                        this.LockOutlay(this._canUnLockOutlay, false);
                        break;
                }
            }
            this.ResetState();
        };
        OutlayVersionsEditor.prototype.LockOutlay = function (canDoIt, canLock) {
            var _this = this;
            if (canDoIt) {
                ObasHelper.DoLongOperation(function () {
                    _this.SourceTable.LockOutlay(canLock);
                });
            }
        };
        OutlayVersionsEditor.prototype.ResetState = function () {
            this._canLockOutlay = false;
            this._canUnLockOutlay = false;
        };
        return OutlayVersionsEditor;
    }(BaseOutlayVersionsEditor));
    FMain.OutlayVersionsEditor = OutlayVersionsEditor;
    var RecipientDetailsEditor = (function (_super) {
        __extends(RecipientDetailsEditor, _super);
        function RecipientDetailsEditor(document) {
            var _this = _super.call(this, ObasTableCollection.SelectedFoivTable.Id + "Editor", document) || this;
            _this._sourceTable = ObasTableCollection.SelectedFoivTable;
            _this._canClose = true;
            return _this;
        }
        Object.defineProperty(RecipientDetailsEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        RecipientDetailsEditor.prototype.IsRecipient = function () {
            return this.SourceTable.IsRecipient();
        };
        RecipientDetailsEditor.prototype.IsManager = function () {
            return this.SourceTable.IsManager() || this.IsRecipient();
        };
        RecipientDetailsEditor.prototype.IsMainManager = function () {
            return this.SourceTable.IsMainManager();
        };
        RecipientDetailsEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            return (this._canClose && buttonResult === MessageResults.Cancel) || buttonResult === MessageResults.Ok;
        };
        RecipientDetailsEditor.prototype.CloseEventHandler = function (exitResult) {
            if (this.SourceTable.RowCount === 0) {
                Client.Exit();
            }
        };
        RecipientDetailsEditor.prototype.GetMainButtonVisible = function (tableId, fieldId, buttonId, isVisible) {
            switch (buttonId) {
                case ClientButton.EditorCancelButton.Id:
                    return this._canClose;
                default:
                    return true;
            }
        };
        RecipientDetailsEditor.prototype.Show = function (mode, canClose) {
            if (canClose === void 0) { canClose = true; }
            this._canClose = canClose;
            var result = _super.prototype.Show.call(this, mode);
            this._canClose = true;
            return result;
        };
        return RecipientDetailsEditor;
    }(BaseEditor));
    FMain.RecipientDetailsEditor = RecipientDetailsEditor;
    var KbkEditor = (function (_super) {
        __extends(KbkEditor, _super);
        function KbkEditor(document) {
            var _this = _super.call(this, "KBKEditor", document) || this;
            _this._sourceTable = ObasTableCollection.RroDataTable;
            return _this;
        }
        KbkEditor.prototype.OnCanCloseEventHandler = function (buttonResult) {
            var isValid = this._sourceTable.GetObasKey() != null;
            if ((!isValid) && (buttonResult === MessageResults.Ok)) {
                Client.ShowMessage("Некорректный КБК", "Выберите корректный набор элементов КБК!");
            }
            return buttonResult === MessageResults.Cancel || (isValid && buttonResult === MessageResults.Ok);
        };
        KbkEditor.prototype.CloseEventHandler = function (isSuccess) {
            if (isSuccess) {
                this._sourceTable.CreateSynonym();
            }
        };
        return KbkEditor;
    }(BaseEditor));
    FMain.KbkEditor = KbkEditor;
    var SumEditor = (function (_super) {
        __extends(SumEditor, _super);
        function SumEditor(id, document, _sourceTable, _sourceTableCaption, _sumTableCaption) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = _sourceTable;
            _this._sourceTableCaption = _sourceTableCaption;
            _this._sumTableCaption = _sumTableCaption;
            _this._sumTable = new AggrTransposedObasTable("tSum" + _sourceTable.Id, [], []);
            return _this;
        }
        SumEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var message = null;
                for (var i = 1; i <= ObasStageSettings.YearsCount; i++) {
                    var borderVal = this.GetBorderValue(i) || 0;
                    var curVal = this._sumTable.GetFieldValue(BaseObasTableFields.YearDataField.GenerateId(i));
                    if (curVal > borderVal) {
                        message = "\u0421\u0443\u043C\u043C\u0430 \u0434\u043E\u0447\u0435\u0440\u043D\u0438\u0445 " + this._sourceTableCaption + ": " + ObasHelper.ConvertToString(curVal, 2) + " \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u0434\u043E\u043F\u0443\u0441\u0442\u0438\u043C\u0443\u044E \u0441\u0443\u043C\u043C\u0443 \u043F\u043E " + this._sumTableCaption + ": " + ObasHelper.ConvertToString(borderVal, 2);
                        break;
                    }
                }
                if (message) {
                    Client.ShowMessage("Ошибка", message, MessageIcons.Error);
                }
                return (message == null && buttonResult === MessageResults.Ok);
            }
        };
        return SumEditor;
    }(BaseEditor));
    var OutlayKosguSumEditor = (function (_super) {
        __extends(OutlayKosguSumEditor, _super);
        function OutlayKosguSumEditor(id, document) {
            return _super.call(this, id, document, ObasTableCollection.RroOutlayKosguTable, "КОСГУ", "форме") || this;
        }
        OutlayKosguSumEditor.prototype.GetBorderValue = function (yearIndex) {
            return ObasTableCollection.RroOutlayKosguTable.RroObasVersion.SourceTable
                .GetFieldValue(BaseObasTableFields.YearDataField.GenerateId(yearIndex));
        };
        return OutlayKosguSumEditor;
    }(SumEditor));
    FMain.OutlayKosguSumEditor = OutlayKosguSumEditor;
    var ObasAddAnalysisIndicatorSumEditor = (function (_super) {
        __extends(ObasAddAnalysisIndicatorSumEditor, _super);
        function ObasAddAnalysisIndicatorSumEditor(id, document) {
            return _super.call(this, id, document, ObasTableCollection.RroObasAddAnalysisIndicatorTable, "аналитических показателей", "КОСГУ") || this;
        }
        ObasAddAnalysisIndicatorSumEditor.prototype.GetBorderValue = function (yearIndex) {
            return ObasTableCollection.RroObasAddAnalysisIndicatorTable.RroOutlayKosguKey.SourceTable
                .GetFieldValue(BaseObasTableFields.YearDataField.GenerateId(yearIndex));
        };
        return ObasAddAnalysisIndicatorSumEditor;
    }(SumEditor));
    FMain.ObasAddAnalysisIndicatorSumEditor = ObasAddAnalysisIndicatorSumEditor;

    var ProcurementPlanVersionsEditor = (function (_super) {
        __extends(ProcurementPlanVersionsEditor, _super);
        function ProcurementPlanVersionsEditor(id, document) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = ObasTableCollection.RroProcurementPlanTable;
            _this._errorMsg = null;
            _this._warningMsg = null;
            return _this;
        }
        Object.defineProperty(ProcurementPlanVersionsEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        ProcurementPlanVersionsEditor.prototype.IsApproved = function () {
            return this._sourceTable.Status === ProcurementPlanStatuses.Approved;
        };
        ProcurementPlanVersionsEditor.prototype.IsAgreed = function () {
            return this._sourceTable.Status === ProcurementPlanStatuses.Agreed;
        };
        ProcurementPlanVersionsEditor.prototype.FilterStatuses = function () {
            var status = ObasTableCollection.ProcurementPlanStatusSprTable.Status;
            switch (this._sourceTable.Status) {
                case ProcurementPlanStatuses.Draft:
                    return (status === ProcurementPlanStatuses.Draft ||
                        status === ProcurementPlanStatuses.AgreeSubmit);
                case ProcurementPlanStatuses.AgreeSubmit:
                    return (status === ProcurementPlanStatuses.Draft ||
                        status === ProcurementPlanStatuses.AgreeSubmit ||
                        status === ProcurementPlanStatuses.Agreed);
                case ProcurementPlanStatuses.Agreed:
                    return (status === ProcurementPlanStatuses.AgreeSubmit ||
                        status === ProcurementPlanStatuses.Agreed ||
                        status === ProcurementPlanStatuses.ApproveSubmit);
                case ProcurementPlanStatuses.ApproveSubmit:
                    return (status === ProcurementPlanStatuses.Agreed ||
                        status === ProcurementPlanStatuses.ApproveSubmit ||
                        status === ProcurementPlanStatuses.Approved);
                default:
                    return true;
            }
        };
        ProcurementPlanVersionsEditor.prototype.VerifySumbyKBK = function () {
            var errorMsg = null;
            var procurementTable = ObasTableCollection.RroProcurementTable;
            var procurementSumbyKBKTable = ObasTableCollection.RroProcurementSumbyKBKTable;
            procurementSumbyKBKTable.DeleteAllRow();
            while (procurementTable.Locate(procurementTable.ProcurementPlanKey.Id, this.SourceTable.RecordKey.Value, true)) {
                procurementSumbyKBKTable.UpdateDataRows(procurementTable.RecordKey.Value);
            }
            procurementTable.ClearLocateFlag();
            var versionsTable = ObasTableCollection.RroObasVersionsTable;
            var locateFieldIds = procurementSumbyKBKTable.GetKbkKeyFieldsId();
            locateFieldIds.push(ObasTableCollection.RroDataTable.RroOutlayKey.Id);
            var keyLastApprovedOutlay = ObasTableCollection.RroProcurementKBKTable.GetKeyLastApprovedOutlay();
            var reader = procurementSumbyKBKTable.CreateReader();
            while (reader.Read()) {
                var locateValues = procurementSumbyKBKTable.GetKbkKeyFieldsValue();
                locateValues.push(keyLastApprovedOutlay);

//                        Client.ShowMessage("", procurementSumbyKBKTable.CalcKBKFullName() + "  Y1 = " + procurementSumbyKBKTable.GetFieldValue("Y1") + "   Y2 = " + procurementSumbyKBKTable.GetFieldValue("Y2") + "   Y3 = " + procurementSumbyKBKTable.GetFieldValue("Y3"), MessageIcons.Information);

                while (versionsTable.Locate(locateFieldIds, locateValues, true)) {
                    for (var i = 0; i <= ObasStageSettings.YearsCount - 1; i++) {
                        var fieldId = "Y" + (i + 1);
                        var curValue = procurementSumbyKBKTable.GetFieldValue(fieldId) || 0;
                        var subValue = versionsTable.GetFieldValue(fieldId) || 0;
                        procurementSumbyKBKTable.SetFieldValue(fieldId, curValue - subValue);
                    }
                }
                versionsTable.ClearLocateFlag();

//                        Client.ShowMessage("", procurementSumbyKBKTable.CalcKBKFullName() + "  Y1 = " + procurementSumbyKBKTable.GetFieldValue("Y1") + "   Y2 = " + procurementSumbyKBKTable.GetFieldValue("Y2") + "   Y3 = " + procurementSumbyKBKTable.GetFieldValue("Y3"), MessageIcons.Information);

                for (var i = 0; i <= ObasStageSettings.YearsCount - 1; i++) {
                    var fieldId = "Y" + (i + 1);
                    if (procurementSumbyKBKTable.GetFieldValue(fieldId) > 0) {
                        errorMsg = "\u041F\u043E \u041A\u0411\u041A = \"" + procurementSumbyKBKTable.GetKbkCode().replace(/null/g, "") + "\" \u0441\u0443\u043C\u043C\u0430 \u041B\u0411\u041E \u043D\u0430 " + (ObasStageSettings.CurrentYear + i) + " \u0433\u043E\u0434 \u0432 \u041F\u043B\u0430\u043D\u0435 \u0437\u0430\u043A\u0443\u043F\u043E\u043A \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u0441\u0443\u043C\u043C\u0443 \u0432 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u043D\u043E\u0439 \u0411\u044E\u0434\u0436\u0435\u0442\u043D\u043E\u0439 \u0441\u043C\u0435\u0442\u0435";
                        break;
                    }
                }
                if (errorMsg != null) {
                    break;
                }
            }
            return errorMsg;
        };
        ProcurementPlanVersionsEditor.prototype.VerifyVersion = function () {
            var errorMsg = null;
            var procurementTable = ObasTableCollection.RroProcurementTable;
            var okpdTable = ObasTableCollection.RroProcurementOKPDTable;
            var kbkTable = ObasTableCollection.RroProcurementKBKTable;
            var npaTable = ObasTableCollection.RroProcurementNPATable;
            while (procurementTable.Locate(procurementTable.ProcurementPlanKey.Id, this.SourceTable.RecordKey.Value, true)) {
                if (procurementTable.GroundsMakingChangesKey.Value === null) {
                    var countOKPD = okpdTable.RowCountProcurement(procurementTable.RecordKey.Value);
                    var countKBK = kbkTable.RowCountProcurement(procurementTable.RecordKey.Value);
                    var countNPA = npaTable.RowCountProcurement(procurementTable.RecordKey.Value);
                    if ((countOKPD === 0) || (countKBK === 0) || (countNPA === 0)) {
                        errorMsg = "\u0412 \u0437\u0430\u043A\u0443\u043F\u043A\u0435 \u0441 \u0418\u041A\u0417 = \"" + procurementTable.IKZ.Value + "\" \u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D ";
                        var arrErrorMsg = [];
                        if (countOKPD === 0) {
                            arrErrorMsg.push("\u041E\u041A\u041F\u0414");
                        }
                        if (countKBK === 0) {
                            arrErrorMsg.push("\u041A\u0411\u041A");
                        }
                        if (countNPA === 0) {
                            arrErrorMsg.push("\u041D\u041F\u0410");
                        }
                        errorMsg = errorMsg + arrErrorMsg[0];
                        if (arrErrorMsg.length === 3) {
                            errorMsg = errorMsg + ", " + arrErrorMsg[1] + " \u0438 " + arrErrorMsg[2];
                        }
                        else if (arrErrorMsg.length === 2) {
                            errorMsg = errorMsg + " \u0438 " + arrErrorMsg[1];
                        }
                        break;
                    }
                    if ((procurementTable.ProcurementTypeKey.Value === 1) &&
                        (procurementTable.IsEnlargedKey.Value === ObasTableCollection.BooleanSprTable.GetTrueId()) &&
                        (countOKPD < 2)) {
                        errorMsg = "\u0423 \u0443\u043A\u0440\u0443\u043F\u043D\u0435\u043D\u043D\u043E\u0439 \u0437\u0430\u043A\u0443\u043F\u043A\u0438 \u0441 \u0418\u041A\u0417 = \"" + procurementTable.IKZ.Value + "\" \u043A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u0437\u0430\u043F\u0438\u0441\u0435\u0439 \u041E\u041A\u041F\u0414 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0431\u043E\u043B\u044C\u0448\u0435 \u043E\u0434\u043D\u043E\u0439", MessageIcons.Error;
                        ;
                        break;
                    }
                    var isSameOKPD = okpdTable.CheckWithPrevVersion(procurementTable.RecordKey.Value, procurementTable.ParentKey.Value);
                    var isSameKBK = kbkTable.CheckWithPrevVersion(procurementTable.RecordKey.Value, procurementTable.ParentKey.Value);
                    var isSameNPA = npaTable.CheckWithPrevVersion(procurementTable.RecordKey.Value, procurementTable.ParentKey.Value);
                    if (!isSameOKPD || !isSameKBK || !isSameNPA) {
                        errorMsg = "\u0417\u0430\u043A\u0443\u043F\u043A\u0430 \u0441 \u0418\u041A\u0417 = \"" + procurementTable.IKZ.Value + "\" \u0431\u044B\u043B\u0430 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0430. \u0412 \u0441\u0442\u0440\u043E\u043A\u0435 \u0434\u0430\u043D\u043D\u043E\u0439 \u0437\u0430\u043A\u0443\u043F\u043A\u0438 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E \u0437\u0430\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043F\u043E\u043B\u0435 \"\u041E\u0441\u043D\u043E\u0432\u0430\u043D\u0438\u0435 \u0432\u043D\u0435\u0441\u0435\u043D\u0438\u044F \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439\"", MessageIcons.Error;
                        ;
                        break;
                    }
                }
            }
            procurementTable.ClearLocateFlag();
            return errorMsg;
        };
        ProcurementPlanVersionsEditor.prototype.EditFieldEventHandler = function (sheetId, fieldId, newValue, oldValue) {
            switch (fieldId) {
                case this._sourceTable.StatusSprField.ForeignKey.Id:
                    if (this._sourceTable.Status != ProcurementPlanStatuses.AgreeSubmit) {
                        this._errorMsg = null;
                    }
                    else {
                        Client.SetCursorType(TypeCursor.crHourGlass);
                        this._errorMsg = this.VerifyVersion();
                        if (this._errorMsg === null) {
                            this._warningMsg = this.VerifySumbyKBK();
                        }
                        Client.SetCursorType(TypeCursor.crDefault);
                    }
                    break;
            }
            return true;
        };
        ProcurementPlanVersionsEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                this._errorMsg = null;
                return true;
            }
            else {
                if (this._errorMsg != null) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", this._errorMsg, MessageIcons.Error);
                }
                else if (this._warningMsg != null) {
                    Client.ShowMessage("\u0412\u043D\u0438\u043C\u0430\u043D\u0438\u0435", this._warningMsg, MessageIcons.Warning);
                    this._warningMsg = null;
                }
                return (this._errorMsg === null && buttonResult === MessageResults.Ok);
            }
        };
        return ProcurementPlanVersionsEditor;
    }(BaseEditor));
    FMain.ProcurementPlanVersionsEditor = ProcurementPlanVersionsEditor;
    var ProcurementsEditor = (function (_super) {
        __extends(ProcurementsEditor, _super);
        function ProcurementsEditor(id, document) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = ObasTableCollection.RroProcurementTable;
            _this._isUniqueNumStr = true;
            _this._canAddProcurementType = true;
            return _this;
        }
        Object.defineProperty(ProcurementsEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        ProcurementsEditor.prototype.IsEnlargedFieldVisible = function () {
            return this.SourceTable.ProcurementTypeKey.Value === 1;
        };
        ProcurementsEditor.prototype.IsGroundsMakingChangesFieldVisible = function () {
            var procurementPlanTable = this.SourceTable._procurementPlanTable;
            return (this.Mode === EditorShowMode.Edit) && (procurementPlanTable.RowCount > 1) && (procurementPlanTable.IsDraft());
        };
        ProcurementsEditor.prototype.IsRequiredDatesPeriod = function () {
            return (this.SourceTable.DateBegin.Value != null) || (this.SourceTable.DateEnd.Value != null);
        };
        ProcurementsEditor.prototype.IsCorrectYearDate = function () {
            var placementYear = this.SourceTable.GetPlacementYear();
            var dateBegin = this.SourceTable.DateBegin.Value;
            return (dateBegin === null) || (dateBegin.getFullYear() === placementYear);
        };
        ProcurementsEditor.prototype.IsCorrectDatesPeriod = function () {
            var dateBegin = this.SourceTable.DateBegin.Value;
            var dateEnd = this.SourceTable.DateEnd.Value;
            return (dateBegin === null) || (dateEnd === null) || (dateBegin <= dateEnd);
        };
        ProcurementsEditor.prototype.IsCorrectProcurementPeriod = function () {
            return ((this.SourceTable.DateBegin.Value != null) && (this.SourceTable.DateEnd.Value != null)) || (this.SourceTable.PeriodicityKey.Value != null);
        };
        ProcurementsEditor.prototype.FilterGroundsMakingChanges = function () {
            var dateStart = ObasTableCollection.GroundsMakingChangesTable.DateStart.Value;
            var dateEnd = ObasTableCollection.GroundsMakingChangesTable.DateEnd.Value;
            var curDate = ObasHelper.GetToday(); // ObasHelper.ConvertStringToDate("15.11.2017");
            return (curDate >= dateStart) && (curDate < dateEnd);
        };
        ProcurementsEditor.prototype.EditFieldEventHandler = function (sheetId, fieldId, newValue, oldValue) {
            switch (fieldId) {
                case this.SourceTable.NumStr.Id:
                    this._isUniqueNumStr = this.SourceTable.IsUniqueNumStr(this.SourceTable.NumStr.Value, this.SourceTable.PlacementYearKey.Value);
                    break;
                case this.SourceTable.ProcurementTypeKey.Id:
                case this.SourceTable.PlacementYearKey.Id:
                    this._canAddProcurementType = this.SourceTable.CanAddProcurementType(this.SourceTable.ProcurementTypeKey.Value, this.SourceTable.PlacementYearKey.Value);
                    break;
                case this.SourceTable.PeriodicityKey.Id:
                    if (this.SourceTable.PeriodicityKey.Value === 0) {
                        this.SourceTable.PeriodicityKey.Value = null;
                    }
                    break;
            }
            return true;
        };
        ProcurementsEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var isCorrectYearDate = this.IsCorrectYearDate();
                var isCorrectDatesPeriod = this.IsCorrectDatesPeriod();
                var isCorrectProcurementPeriod = this.IsCorrectProcurementPeriod();
                if (!this._isUniqueNumStr) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043A\u0443\u043F\u043A\u0430 \u0441 \u041D\u043E\u043C\u0435\u0440\u043E\u043C = \"" + this.SourceTable.NumStr.Value + "\" \u0438 \u0413\u043E\u0434\u043E\u043C \u0440\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u044F \u0438\u0437\u0432\u0435\u0449\u0435\u043D\u0438\u044F = \"" + this.SourceTable.GetFieldValue("Procurement_PlacementYear_Name") + "\"", MessageIcons.Error);
                }
                else if (!this._canAddProcurementType) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0437\u0430\u043A\u0443\u043F\u043A\u0430 \u0441 \u0422\u0438\u043F\u043E\u043C \u0437\u0430\u043A\u0443\u043F\u043A\u0438 = \"" + this.SourceTable.GetFieldValue("Procurement_Types_Name") + "\" \u0438 \u0413\u043E\u0434\u043E\u043C \u0440\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u044F \u0438\u0437\u0432\u0435\u0449\u0435\u043D\u0438\u044F = \"" + this.SourceTable.GetFieldValue("Procurement_PlacementYear_Name") + "\"", MessageIcons.Error);
                }
                else if (!isCorrectProcurementPeriod) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u041D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E \u0437\u0430\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043B\u0438\u0431\u043E \u0434\u0430\u0442\u044B \u043D\u0430\u0447\u0430\u043B\u0430 \u0438 \u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u044F \u0437\u0430\u043A\u0443\u043F\u043A\u0438, \u043B\u0438\u0431\u043E \u043F\u0435\u0440\u0438\u043E\u0434\u0438\u0447\u043D\u043E\u0441\u0442\u044C \u043E\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043B\u0435\u043D\u0438\u044F \u0437\u0430\u043A\u0443\u043F\u043A\u0438, \u043B\u0438\u0431\u043E \u0438 \u0442\u043E \u0438 \u0434\u0440\u0443\u0433\u043E\u0435", MessageIcons.Error);
                }
                else if (!isCorrectYearDate) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0414\u0430\u0442\u0430 \u043D\u0430\u0447\u0430\u043B\u0430 \u0437\u0430\u043A\u0443\u043F\u043A\u0438 \u0434\u043E\u043B\u0436\u043D\u0430 \u0431\u044B\u0442\u044C \u0432 \u043F\u0440\u0435\u0434\u0435\u043B\u0430\u0445 \u0433\u043E\u0434\u0430 \u0440\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u044F", MessageIcons.Error);
                }
                else if (!isCorrectDatesPeriod) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0414\u0430\u0442\u0430 \u043D\u0430\u0447\u0430\u043B\u0430 \u0437\u0430\u043A\u0443\u043F\u043A\u0438 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u0431\u043E\u043B\u044C\u0448\u0435 \u0434\u0430\u0442\u044B \u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u044F \u0437\u0430\u043A\u0443\u043F\u043A\u0438", MessageIcons.Error);
                }
                return (this._isUniqueNumStr && this._canAddProcurementType && isCorrectProcurementPeriod && isCorrectYearDate && isCorrectDatesPeriod && buttonResult === MessageResults.Ok);
            }
        };
        return ProcurementsEditor;
    }(BaseEditor));
    FMain.ProcurementsEditor = ProcurementsEditor;
    var ProcurementsOKPDEditor = (function (_super) {
        __extends(ProcurementsOKPDEditor, _super);
        function ProcurementsOKPDEditor(id, document) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = ObasTableCollection.RroProcurementOKPDTable;
            return _this;
        }
        Object.defineProperty(ProcurementsOKPDEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ProcurementsOKPDEditor.prototype, "ProcurementTable", {
            get: function () {
                return this._sourceTable._procurementTable;
            },
            enumerable: true,
            configurable: true
        });
        ProcurementsOKPDEditor.prototype.FilterOKPD = function () {
            var okpdCode = ObasTableCollection.OkpdSprTable.Code.Value || "";
            return okpdCode.length >= 5;
        };
        ProcurementsOKPDEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            this._isResultOk = (buttonResult === MessageResults.Ok);
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var isValid = this.SourceTable.IsUniqueOKPDbyProcumerent(this.SourceTable.ProcurementKey.Value, this.SourceTable.OKPDKey.Value);
                if (!isValid) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043E\u043A\u0430 \u0441 \u041E\u041A\u041F\u0414 = \"" + this.SourceTable.OKPDCode + "\"", MessageIcons.Error);
                }
                return (isValid && buttonResult === MessageResults.Ok);
            }
        };
        return ProcurementsOKPDEditor;
    }(BaseEditor));
    FMain.ProcurementsOKPDEditor = ProcurementsOKPDEditor;
    var ProcurementsKBKEditor = (function (_super) {
        __extends(ProcurementsKBKEditor, _super);
        function ProcurementsKBKEditor(id, document) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = ObasTableCollection.RroProcurementKBKTable;
            _this._isUniqueKBK = true;
            _this._lastApprovedOutlayKey = null;
            return _this;
        }
        Object.defineProperty(ProcurementsKBKEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(ProcurementsKBKEditor.prototype, "LastApprovedOutlayKey", {
            get: function () {
                if (this._lastApprovedOutlayKey == null) {
                    this._lastApprovedOutlayKey = this.SourceTable.GetKeyLastApprovedOutlay();
                }
                return this._lastApprovedOutlayKey;
            },
            enumerable: true,
            configurable: true
        });
        ProcurementsKBKEditor.prototype.GetKbkCode = function () {
            return this.SourceTable.GetKbkCode().replace(/null/g, "");
        };
        ProcurementsKBKEditor.prototype.FilterKBK = function () {
            return (ObasTableCollection.RroDataTable.RroOutlayKey.Value === this.LastApprovedOutlayKey);
        };
        ProcurementsKBKEditor.prototype.EditFieldEventHandler = function (sheetId, fieldId, newValue, oldValue) {
            if (fieldId === "RRO_Data_ID") {
                this._isUniqueKBK = this.SourceTable.IsUniqueKBKbyProcumerent(this.SourceTable.ProcurementKey.Value);
            }
            return true;
        };
        ProcurementsKBKEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var isCorrectKBK = this.SourceTable.IsCorrectKBK();
                if (!isCorrectKBK) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u041D\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043E\u043A\u0430 \u0441 \u041A\u0411\u041A = \"" + this.GetKbkCode() + "\" \u0432 \u043F\u043E\u0441\u043B\u0435\u0434\u043D\u0435\u0439 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D\u043D\u043E\u0439 \u0441\u043C\u0435\u0442\u0435", MessageIcons.Error);
                }
                else if (!this._isUniqueKBK) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0442\u0440\u043E\u043A\u0430 \u0441 \u041A\u0411\u041A = \"" + this.GetKbkCode() + "\"", MessageIcons.Error);
                }
                return (isCorrectKBK && this._isUniqueKBK && buttonResult === MessageResults.Ok);
            }
        };
        ProcurementsKBKEditor.prototype.CloseEventHandler = function (isSuccess) {
            this._lastApprovedOutlayKey = null;
        };
        return ProcurementsKBKEditor;
    }(BaseEditor));
    FMain.ProcurementsKBKEditor = ProcurementsKBKEditor;
    var ProcurementsNPAEditor = (function (_super) {
        __extends(ProcurementsNPAEditor, _super);
        function ProcurementsNPAEditor(id, document) {
            var _this = _super.call(this, id, document) || this;
            _this._sourceTable = ObasTableCollection.RroProcurementNPATable;
            return _this;
        }
        Object.defineProperty(ProcurementsNPAEditor.prototype, "SourceTable", {
            get: function () {
                return this._sourceTable;
            },
            enumerable: true,
            configurable: true
        });
        ProcurementsNPAEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var isValid = (this.SourceTable.ActDate.Value <= ObasHelper.GetToday());
                if (!isValid) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0414\u0430\u0442\u0430 \u041D\u041F\u0410 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u0431\u043E\u043B\u044C\u0448\u0435 \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0434\u0430\u0442\u044B", MessageIcons.Error);
                }
                return (isValid && buttonResult === MessageResults.Ok);
            }
        };
        return ProcurementsNPAEditor;
    }(BaseEditor));
    FMain.ProcurementsNPAEditor = ProcurementsNPAEditor;
})(FMain || (FMain = {}));
