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.NeedFillChangeType = function () {
            return (this._sourceTable.Status === OutlayStatuses.Draft) && (this._sourceTable.Number.Value.substr(0, 4) === "3-61");
        };
        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) {
            this.Document.ProcurementPlanVersionsSheet.Refresh();
            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.VerifyExistsApprovedOutlay = function () {
            var errorMsg = null;
            var rroOutlayTable = ObasTableCollection.RroOutlayTable;
            if (!rroOutlayTable.Locate(rroOutlayTable.StatusSprField.ForeignKey.Id, OutlayStatuses.Approved)) {
                errorMsg = "\u0414\u043E\u043A\u0443\u043C\u0435\u043D\u0442 \"\u0411\u044E\u0434\u0436\u0435\u0442\u043D\u0430\u044F \u0441\u043C\u0435\u0442\u0430\" \u043D\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043D. \u0421\u043E\u0433\u043B\u0430\u0441\u043E\u0432\u0430\u043D\u0438\u0435 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430 \u043D\u0435 \u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E.";
            }
            return errorMsg;
        };
        ProcurementPlanVersionsEditor.prototype.VerifySumbyKBK = function () {
            var errorMsg = null;
            var procurementTable = ObasTableCollection.RroProcurementTable;
            var procurementPlanSumbyKBKTable = ObasTableCollection.RroProcurementPlanSumbyKBKTable;
            procurementPlanSumbyKBKTable.UpdateDataRows(this.SourceTable.RecordKey.Value);
            var versionsTable = ObasTableCollection.RroObasVersionsTable;
            var locateFieldIds = procurementPlanSumbyKBKTable.GetKbkKeyFieldsId();
            locateFieldIds.push(ObasTableCollection.RroDataTable.RroOutlayKey.Id);
            var keyLastApprovedOutlay = ObasTableCollection.RroProcurementKBKTable.GetKeyLastApprovedOutlay();
            var reader = procurementPlanSumbyKBKTable.CreateReader();
            while (reader.Read()) {
                var locateValues = procurementPlanSumbyKBKTable.GetKbkKeyFieldsValue();
                locateValues.push(keyLastApprovedOutlay);

//                        Client.ShowMessage("", procurementPlanSumbyKBKTable.CalcKBKFullCode() + "  Y1 = " + procurementPlanSumbyKBKTable.GetFieldValue("Y1") + "   Y2 = " + procurementPlanSumbyKBKTable.GetFieldValue("Y2") + "   Y3 = " + procurementPlanSumbyKBKTable.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 = procurementPlanSumbyKBKTable.GetFieldValue(fieldId) || 0;
                        var subValue = versionsTable.GetFieldValue(fieldId) || 0;
                        procurementPlanSumbyKBKTable.SetFieldValue(fieldId, curValue - subValue);
                    }
                }
                versionsTable.ClearLocateFlag();

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

                for (var i = 0; i <= ObasStageSettings.YearsCount - 1; i++) {
                    var fieldId = "Y" + (i + 1);
                    if (procurementPlanSumbyKBKTable.GetFieldValue(fieldId) > 0) {
                        errorMsg = "\u041F\u043E \u041A\u0411\u041A = \"" + procurementPlanSumbyKBKTable.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.VerifyProcurementInfoNPA = function (procurementKey) {
            var result = false;
            var infoNPATable = ObasTableCollection.RroProcurementInfoNPATable;
            var infoNPADetailsTable = ObasTableCollection.RroProcurementInfoNPADetailsTable;
            while (infoNPATable.Locate(infoNPATable.ProcurementKey.Id, procurementKey, true)) {
                while (infoNPADetailsTable.Locate(infoNPADetailsTable.InfoNPAKey.Id, infoNPATable.RecordKey.Value, true)) {
                    result = true;
                    break;
                }
                infoNPADetailsTable.ClearLocateFlag();
                if (result) {
                    break;
                }
            }
            infoNPATable.ClearLocateFlag();
            return result;
        };
        ProcurementPlanVersionsEditor.prototype.VerifyVersion = function () {
            var errorMsg = null;
            var errorNum = 0;
            var procurementTable = ObasTableCollection.RroProcurementTable;
            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 countKBK = kbkTable.RowCountProcurement(procurementTable.RecordKey.Value);
                    var countOKPD = countKBK;
                    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 \u043D\u0430 \u0432\u043A\u043B\u0430\u0434\u043A\u0435 \"\u0414\u0435\u0442\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F \u043F\u043E \u041A\u0411\u041A\" \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u043D\u0435 \u043C\u0435\u043D\u0435\u0435 \u0434\u0432\u0443\u0445";
                        break;
                    }
                    var isSameKBK = kbkTable.CheckWithPrevVersion(procurementTable.RecordKey.Value, procurementTable.ParentKey.Value);
                    var isSameNPA = npaTable.CheckWithPrevVersion(procurementTable.RecordKey.Value, procurementTable.ParentKey.Value);
                    if (!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\"";
                        break;
                    }
                }
                var existsEmptyOKPD = kbkTable.ExistsEmptyOKPDbyProcurement(procurementTable.RecordKey.Value);
                if (existsEmptyOKPD) {
                    if (errorMsg === null) {
                        errorMsg = "\u0412 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0445 \u0418\u041A\u0417 \u0438\u043C\u0435\u044E\u0442\u0441\u044F \u041A\u0411\u041A \u043F\u043E \u043A\u043E\u0442\u043E\u0440\u044B\u043C \u043D\u0435 \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u043E \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u041E\u041A\u041F\u0414:";
                        errorNum = 4;
                    }
                    if (errorNum === 4) {
                        errorMsg = errorMsg + ("\n\"" + procurementTable.IKZ.Value + "\"");
                    }
                }
                while (kbkTable.Locate(kbkTable.ProcurementKey.Id, procurementTable.RecordKey.Value, true)) {
                    var existsKBKinLastOutlay = kbkTable.ExistsKBKinLastOutlay();
                    if (!existsKBKinLastOutlay) {
                        if (errorMsg === null) {
                            errorMsg = "\u0412 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0435 \"\u041F\u043B\u0430\u043D \u0437\u0430\u043A\u0443\u043F\u043E\u043A\" \u0438\u043C\u0435\u044E\u0442\u0441\u044F \u041A\u0411\u041A, \u043A\u043E\u0442\u043E\u0440\u044B\u0435 \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044E\u0442 \u0432 \u0440\u0430\u0437\u0434\u0435\u043B\u0435 \"\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u0435\u043B\u0438 \u0431\u044E\u0434\u0436\u0435\u0442\u043D\u044B\u0445 \u0441\u043C\u0435\u0442\":";
                            errorNum = 5;
                        }
                        if (errorNum === 5) {
                            errorMsg = errorMsg + ("\n\u0418\u041A\u0417 = \"" + procurementTable.IKZ.Value + "\",\n\u041A\u0411\u041A = \"" + kbkTable.CalcKBKFullCode().replace(/null/g, "") + "\";");
                        }
                    }
                }
                kbkTable.ClearLocateFlag();
                var existsBlankDataNPA = npaTable.ExistsBlankDatabyProcurement(procurementTable.RecordKey.Value);
                if (existsBlankDataNPA) {
                    if (errorMsg === null) {
                        errorMsg = "\u0412 \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u0445 \u0418\u041A\u0417 \u0438\u043C\u0435\u044E\u0442\u0441\u044F \u041D\u041F\u0410, \u0443 \u043A\u043E\u0442\u043E\u0440\u044B\u0445 \u043D\u0435 \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B \u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B\u0435 \u043F\u043E\u043B\u044F:";
                        errorNum = 6;
                    }
                    if (errorNum === 6) {
                        errorMsg = errorMsg + ("\n\"" + procurementTable.IKZ.Value + "\"");
                    }
                }
                if (((procurementTable.GetFieldValue("Y4") || 0) > 0) && !this.VerifyProcurementInfoNPA(procurementTable.RecordKey.Value)) {
                    if (errorMsg === null) {
                        errorMsg = "\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043E\u0442\u043C\u0435\u043D\u0435\u043D\u043E, \u0442.\u043A. \u043F\u043E \u0441\u043B\u0435\u0434\u0443\u044E\u0449\u0438\u043C \u0418\u041A\u0417 \u043D\u0435 \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B \u0441\u0432\u0435\u0434\u0435\u043D\u0438\u044F \u043E\u0431 \u041D\u041F\u0410, \u043F\u043E \u043E\u0431\u044A\u0435\u043C\u0430\u043C \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u044E\u0449\u0438\u043C \u0441\u0440\u043E\u043A \u041B\u0411\u041E:";
                        errorNum = 7;
                    }
                    if (errorNum === 7) {
                        errorMsg = errorMsg + ("\n\"" + procurementTable.IKZ.Value + "\"");
                    }
                }
            }
            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.VerifyExistsApprovedOutlay();
                        if (this._errorMsg === null) {
                            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.IsProcurementNotSpecial = function () {
            return this.SourceTable.ProcurementTypeKey.Value === 1;
        };
        ProcurementsEditor.prototype.IsProcurementSpecial = function () {
            return !this.IsProcurementNotSpecial();
        };
        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.IsRequiredDescriptionGroundsForChanges = function () {
            var groundsMakingChangesTable = ObasTableCollection.GroundsMakingChangesTable;
            groundsMakingChangesTable.Locate(groundsMakingChangesTable.RecordKey.Id, this.SourceTable.GroundsMakingChangesKey.Value);
            return groundsMakingChangesTable.IsDescriptionRequired.Value;
        };
        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 isCorrectNumStr = (this.SourceTable.NumStr.Value != "0000");
                var isCorrectYearDate = this.IsCorrectYearDate();
                var isCorrectDatesPeriod = this.IsCorrectDatesPeriod();
                var isCorrectProcurementPeriod = this.IsCorrectProcurementPeriod();
                var needClearYearsDataFields = this.SourceTable.NeedClearYearsDataFields();
                if (!isCorrectNumStr) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0417\u0430\u043A\u0443\u043F\u043A\u0430 \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u043C\u0435\u0442\u044C \u041D\u043E\u043C\u0435\u0440 = \"" + this.SourceTable.NumStr.Value + "\"", MessageIcons.Error);
                }
                else 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);
                }
                else if (needClearYearsDataFields) {
                    Client.ShowMessage("\u0418\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044F", "\u041E\u0431\u044A\u0435\u043C\u044B \u0444\u0438\u043D\u0430\u043D\u0441\u043E\u0432\u043E\u0433\u043E \u043E\u0431\u0435\u0441\u043F\u0435\u0447\u0435\u043D\u0438\u044F \u043C\u043E\u0433\u0443\u0442 \u0431\u044B\u0442\u044C \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B \u043F\u043E \u0433\u043E\u0434\u0443 \u0440\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u044F \u0438 \u0432\u044B\u0448\u0435. \u041E\u0431\u044A\u0435\u043C\u044B \u0444\u0438\u043D\u0430\u043D\u0441\u043E\u0432\u043E\u0433\u043E \u043E\u0431\u0435\u0441\u043F\u0435\u0447\u0435\u043D\u0438\u044F \u0431\u0443\u0434\u0443\u0442 \u043E\u0447\u0438\u0449\u0435\u043D\u044B \u043F\u043E \u0434\u0430\u043D\u043D\u043E\u0439 \u0418\u041A\u0417", MessageIcons.Information);
                    this.SourceTable.ClearYearsDataFields();
                }
                return (isCorrectNumStr && 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._lastApprovedOutlayKey = null;
            _this._isUniqueKBK = true;
            _this._isUniqueKBKandOKPD = true;
            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.GetKbkFullCode = function () {
            return this.SourceTable.CalcKBKFullCode().replace(/null/g, "");
        };
        ProcurementsKBKEditor.prototype.FilterKBK = function () {
            return (ObasTableCollection.RroDataTable.RroOutlayKey.Value === this.LastApprovedOutlayKey);
        };
        ProcurementsKBKEditor.prototype.FilterOKPD = function () {
            var okpdCode = ObasTableCollection.OkpdSprTable.Code.Value || "";
            return okpdCode.length >= 5;
        };
        ProcurementsKBKEditor.prototype.IsProcurementSpecial = function () {
            return this.SourceTable.GetProcurementTypeKey() != 1;
        };
        ProcurementsKBKEditor.prototype.IsReadOnlyY1Field = function () {
            return !this.SourceTable.CanEditYearDataField("Y1");
        };
        ProcurementsKBKEditor.prototype.IsReadOnlyY2Field = function () {
            return !this.SourceTable.CanEditYearDataField("Y2");
        };
        ProcurementsKBKEditor.prototype.IsRussianProcurement = function () {
            return !this.SourceTable.IsForeignProcurement.Value;
        };
        ProcurementsKBKEditor.prototype.IsForeignProcurement = function () {
            return this.SourceTable.IsForeignProcurement.Value;
        };
        ProcurementsKBKEditor.prototype.IsReadOnlyFieldIsForeignProcurement = function () {
            var result = false;
            var procurementTable = ObasTableCollection.RroProcurementTable;
            procurementTable.SavePosition();
            if (procurementTable.LocateByKeys(this.SourceTable.ProcurementKey.Value)) {
                result = procurementTable.Locate(procurementTable.RecordKey.Id, procurementTable.ParentKey.Value);
            }
            procurementTable.RestorePosition();
            return result;
        };
        ProcurementsKBKEditor.prototype.ExistsFilledSums = function () {
            var result = false;
            for (var i = 0; i <= ObasStageSettings.YearsCount; i++) {
                var fieldId = "Y" + (i + 1);
                if ((this.SourceTable.GetFieldValue(fieldId) || 0) != 0) {
                    result = true;
                    break;
                }
            }
            return result;
        };
        ProcurementsKBKEditor.prototype.EditFieldEventHandler = function (sheetId, fieldId, newValue, oldValue) {
            if ((fieldId === this.SourceTable.RroDataKey.Id) || (fieldId === this.SourceTable.OKPDKey.Id)) {
                this._isUniqueKBKandOKPD = this.SourceTable.IsUniqueKBKandOKPDbyProcumerent(this.SourceTable.ProcurementKey.Value);
            }
            else if (fieldId === this.SourceTable.IsForeignProcurement.Id) {
                this.SourceTable.ClearSums();
            }
            return true;
        };
        ProcurementsKBKEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var existsFilledSums = this.ExistsFilledSums();
                if (!this._isUniqueKBKandOKPD) {
                    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.GetKbkFullCode() + "\" \u0438 \u041E\u041A\u041F\u0414 = \"" + this.SourceTable.OKPDCode + "\"", MessageIcons.Error);
                }
                else if (!existsFilledSums) {
                    Client.ShowMessage("\u041E\u0448\u0438\u0431\u043A\u0430", "\u0425\u043E\u0442\u044F \u0431\u044B \u043F\u043E \u043E\u0434\u043D\u043E\u043C\u0443 \u0438\u0437 \u0433\u043E\u0434\u043E\u0432 \u0431\u043B\u043E\u043A\u0430 \"\u041E\u0431\u044A\u0435\u043C \u0444\u0438\u043D\u0430\u043D\u0441\u043E\u0432\u043E\u0433\u043E \u043E\u0431\u0435\u0441\u043F\u0435\u0447\u0435\u043D\u0438\u044F\" \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u044B \u0434\u0430\u043D\u043D\u044B\u0435", MessageIcons.Error);
                }
                return (this._isUniqueKBKandOKPD && existsFilledSums && 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.FilterNPAStatuses = function () {
            var npaStatusesTable = ObasTableCollection.NpaStatusesSprTable;
            return npaStatusesTable.RecordKey.Value === 1 || npaStatusesTable.RecordKey.Value === 2;
        };
        ProcurementsNPAEditor.prototype.CanCloseEventHandler = function (buttonResult) {
            if (buttonResult === MessageResults.Cancel) {
                return true;
            }
            else {
                var isValid = (this.SourceTable.NpaDate.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 = {}));
