public CompanyViewModel()
        {
            LegalFormType = new DictionaryRecordViewModel()
            {
                Id = 1, Name = "ООО", FullName = "Общество с ограниченной ответственностью"
            };

            id_addr = -1;

            id_postal_addr = -1;

            IsChanged  = false;
            IsSelected = false;

            AddressBuildNom = "";
            AddressHouse    = "";
            AddressLitera   = "";
            AddressRoomNom  = "";
            FSRARAddress    = "";

            PostalAddressBuildNom = "";
            PostalAddressHouse    = "";
            PostalAddressLitera   = "";
            PostalAddressRoomNom  = "";
            FSRARPostalAddress    = "";



            AddressForDocument = "";
            PostalCode         = "";
        }
        public CompanyViewModel(CompanyExportFromDatabase cc)
        {
            Company c = cc.company;

            Id            = c.Id;
            FullName      = c.FullName;
            CompanyName   = c.Name;
            ShortName     = c.ShortName;
            INN           = c.INN;
            KPP           = c.KPP;
            LegalFormType = new DictionaryRecordViewModel()
            {
                Name = cc.legal_form_type.ShortName, Id = cc.legal_form_type.Id, FullName = cc.legal_form_type.FullName
            };

            OGRN = c.ORGN;

            id_addr = cc.addr == null ? -1 : cc.addr.Id;

            id_postal_addr = cc.addr_postal == null ? -1 : cc.addr_postal.Id;


            Email              = c.Email;
            Address            = c.ActualAddrStr;
            AddressForDocument = c.AddressForDocument;
            PostalAddress      = c.PostalAddrStr;
            PostalCode         = c.PostalCode;
            DateCreatedStr     = c.DateTimeCreated.ToString();
            Creator            = c.CreatorName;

            Phone = c.Phone;

            CheckingAccount = c.CheckingAccount;
            BanksName       = c.BanksName;

            Fax = c.Fax;

            IsChanged  = false;
            IsSelected = false;

            var act_addr_arr = c.ActualAddrAddon.Split(AddressAddonSep);

            AddressHouse    = act_addr_arr[0];
            AddressBuildNom = act_addr_arr[1];
            AddressLitera   = act_addr_arr[2];
            AddressRoomNom  = act_addr_arr[3];
            FSRARAddress    = c.FSRARActualAddr;

            var post_addr_arr = c.PostalAddrAddon.Split(AddressAddonSep);

            PostalAddressHouse    = post_addr_arr[0];
            PostalAddressBuildNom = post_addr_arr[1];
            PostalAddressLitera   = post_addr_arr[2];
            PostalAddressRoomNom  = post_addr_arr[3];
            FSRARPostalAddress    = c.FSRARPostalAddr;
        }
        //public static DeclarationViewModel GetDeclarationViewModelFromXML(IRepository repository, XElement xDec)
        //{
        //    DeclarationViewModel result = new DeclarationViewModel();
        //    result.SmevId = GetXmlNodeNullableValue(xDec, "SmevId");
        //    Declaration decDB = repository.Declaration.Items.FirstOrDefault(x => x.IsDeleted != true && x.SmevId == result.SmevId);
        //    if (decDB != null)
        //    {
        //        if (decDB.Status == DeclarationStatus.Draft)
        //        {
        //            result = GetDeclarationViewModelById(repository, decDB.Id);
        //        }
        //        else
        //        {
        //            throw new Exception(String.Format("Заявление с кодом {0} уже поступило в обработку в учреждении и не может быть изменено.", result.SmevId));
        //        }
        //    }

        //    result.Status = "Draft";

        //    foreach (var item in xDec.Elements("DeclarationTypes"))
        //    {
        //        result.IsGrantType = item.Value == "Выдача";
        //        result.IsProlongType = item.Value == "Продление";
        //        result.IsReNewType = item.Value == "Переоформление";
        //        result.IsCancelType = item.Value == "Прекращение";
        //        result.IsCloneType = item.Value == "Дубликат";
        //    }

        //    result.Comm = GetXmlNodeNullableValue(xDec, "Comment", false);
        //    result.CountYears = GetXmlNodeIntValue(xDec, "Years", result.IsProlongType);
        //    result.IsPhoneInformation = GetXmlNodeBooleanValue(xDec, "IsPhoneInformation");
        //    result.IsEmailInformation = GetXmlNodeBooleanValue(xDec, "IsEmailInformation");
        //    result.IsMailGetResult = GetXmlNodeBooleanValue(xDec, "IsMailGetResult");
        //    result.IsEMailGetResult = GetXmlNodeBooleanValue(xDec, "IsEMailGetResult");
        //    result.IsPersonGetResult = GetXmlNodeBooleanValue(xDec, "IsPersonGetResult");

        //    result.OtherReason = GetXmlNodeNullableValue(xDec, "CustomReasonForRenew", false);
        //    result.ReasonForRenew = new DictionaryRecordViewModel() { Id = 0 };
        //    foreach (var item in xDec.Elements("ReasonsForRenew"))
        //    {
        //        //TODO: Причины переоформления, реализовать мультипричинность из списка
        //    }

        //    result.MasterName = GetXmlNodeNullableValue(xDec, "Applicant", false);

        //    var xComp = xDec.Element("Company");
        //    var xLic = xComp.Element("License");

        //    String dictTypeStr = GetXmlNodeNullableValue(xLic, "LicensedActivityType");
        //    LicensedActivityType lat = repository.LicensedActivityType.Items.FirstOrDefault(x => x.IsDeleted != true && x.ShortName == dictTypeStr);
        //    if (lat != null)
        //    {
        //        result.LicensedActivityTypeId = lat.Id;
        //        result.LicensedActivityTypeName = lat.ShortName;
        //    }
        //    else
        //    {
        //        throw new Exception(String.Format("Тип лицензируемой деятельности задан неверно: {0}", dictTypeStr));
        //    }

        //    if (decDB == null)
        //    {
        //        result.Company = new CompanyViewModel() { Id = 0 };
        //    }

        //    result.Company.ShortName = GetXmlNodeNullableValue(xComp, "ShortName");
        //    result.Company.FullName = GetXmlNodeNullableValue(xComp, "FullName");
        //    result.Company.INN = GetXmlNodeNullableValue(xComp, "INN");
        //    result.Company.KPP = GetXmlNodeNullableValue(xComp, "KPP", false);
        //    result.Company.OGRN = GetXmlNodeNullableValue(xComp, "OGRN", false);
        //    result.Company.Email = GetXmlNodeNullableValue(xComp, "Email", false);
        //    result.Company.Phone = GetXmlNodeNullableValue(xComp, "Phone", false);
        //    result.Company.Fax = GetXmlNodeNullableValue(xComp, "Fax", false);
        //    result.Company.BanksName = GetXmlNodeNullableValue(xComp, "BankName", false);
        //    result.Company.CheckingAccount = GetXmlNodeNullableValue(xComp, "BankAccount", false);

        //    Company companyDB = repository.Company.Items.FirstOrDefault(x => x.INN == result.Company.INN);

        //    String licenseNumber = GetXmlNodeNullableValue(xLic, "LicenseNumber", false);
        //    License activeLicense = null;
        //    if (companyDB != null)
        //    {
        //        activeLicense = companyDB.Licensee.FirstOrDefault(x => x.Status == LicenseStatus.Active && x.LicensedActivityType == lat);
        //    }
        //    if (!result.IsGrantType)
        //    {
        //        if (activeLicense == null)
        //        {
        //            throw new Exception("Действующая лицензия компании по лицензируемому типу деятельности не найдена. Вы можете претендовать только на выдачу новой лицензии.");
        //        }
        //        else if (activeLicense.Nom != licenseNumber)
        //        {
        //            throw new Exception(String.Format("Номер действующей лицензии компании по лицензируемому типу деятельности {0} не соответствует номеру в заявлении: {1}", activeLicense.Nom, licenseNumber));
        //        }
        //        result.LicenseNumber = activeLicense.Nom;
        //        result.LicenseNomOfBook = activeLicense.NomOfBook;
        //        result.LicenseId = activeLicense.Id;
        //    }
        //    else
        //    {
        //        TypeOfTypeOfResolution ttr = TypeOfTypeOfResolution.Grant;
        //        result.TypeOfType = ttr.ToString();
        //        //TODO: инициализация result.ResolutionTypes
        //        //var resolutionTypesAll = TypeOfResolutionForResolutionViewModel.GetTypeOfResolutionViewModelList(repository, ttr, null);
        //        //foreach (var item in resolutionTypesAll)
        //        //{
        //        //    result.ResolutionTypes.Add(item);
        //        //}

        //        if (activeLicense != null)
        //        {
        //            throw new Exception("Действующая лицензия компании по лицензируемому типу деятельности уже существует. Вы можете претендовать только на продление/переоформление/прекращение действия действующей лицензии.");
        //        }
        //    }

        //    if (decDB != null)
        //    {
        //        if (decDB.INN != result.Company.INN)
        //        {
        //            throw new Exception(String.Format("ИНН компании не может быть изменен при редактировании заявления: {0}", decDB.INN));
        //        }
        //        if (decDB.LicenseNom != licenseNumber)
        //        {
        //            throw new Exception(String.Format("Номер лицензии не может быть изменен при редактировании заявления: {0}", decDB.LicenseNom));
        //        }
        //    }

        //    dictTypeStr = GetXmlNodeNullableValue(xComp, "LegalFormType");
        //    LegalFormType lft = repository.LegalFormType.Items.FirstOrDefault(x => x.IsDeleted != true && x.ShortName == dictTypeStr);
        //    if (lft != null)
        //    {
        //        result.Company.LegalFormType = new DictionaryRecordViewModel() { Name = lft.ShortName, Id = lft.Id };
        //    }
        //    else
        //    {
        //        throw new Exception(String.Format("ОПФ задана неверно: {0}", dictTypeStr));
        //    }

        //    //TODO: Addr
        //    var xAddr = xComp.Element("Addr");
        //    result.Company.Address = GetXmlNodeNullableValue(xAddr, "Address");
        //    result.Company.AddressForDocument = GetXmlNodeNullableValue(xAddr, "AddressForDocument", false);

        //    //TODO: AddrPostal
        //    xAddr = xComp.Element("AddrPostal");
        //    result.Company.PostalAddress = GetXmlNodeNullableValue(xAddr, "Address");

        //    foreach (var item in xDec.Descendants("Unit"))
        //    {
        //        UnitInDeclarationViewModel unitVM = null;
        //        int sysId = GetXmlNodeIntValue(item, "SystemId", false);
        //        String relationKind = GetXmlNodeNullableValue(item, "RelationKind");
        //        Boolean isDeleted = GetXmlNodeBooleanValue(item, "IsDeleted");
        //        List<UnitInDeclarationViewModel> unitList = null;
        //        if (relationKind == "Add")
        //        {
        //            unitList = result.UnitsAdd;
        //        }
        //        else if (relationKind == "Edit")
        //        {
        //            unitList = result.UnitsEdit;
        //        }
        //        else if (relationKind == "Remove")
        //        {
        //            unitList = result.UnitsRemove;
        //        }
        //        if (sysId > 0 && decDB != null)
        //        {
        //            unitVM = unitList.FirstOrDefault(x => x.Id == sysId);
        //        }

        //        if (unitVM == null)
        //        {
        //            if (!isDeleted)
        //            {
        //                unitVM = new UnitInDeclarationViewModel();
        //                unitList.Add(unitVM);
        //            }
        //        }
        //        else
        //        {
        //            if (isDeleted)
        //            {
        //                unitList.Remove(unitVM);
        //            }
        //        }

        //        if (!isDeleted)
        //        {
        //            unitVM.ShortName = GetXmlNodeNullableValue(item, "ShortName");
        //            unitVM.FullName = GetXmlNodeNullableValue(item, "FullName");
        //            unitVM.KPP = GetXmlNodeNullableValue(item, "KPP", false);
        //            unitVM.Status = "None";

        //            dictTypeStr = GetXmlNodeNullableValue(item, "UnitType");
        //            UnitType unitType = repository.UnitType.Items.FirstOrDefault(x => x.IsDeleted != true && x.ShortName == dictTypeStr);
        //            if (unitType != null)
        //            {
        //                unitVM.UnitType = new DictionaryRecordViewModel() { Name = unitType.ShortName, Id = unitType.Id };
        //            }
        //            else
        //            {
        //                throw new Exception(String.Format("Тип подразделения задан неверно: {0}", dictTypeStr));
        //            }

        //            dictTypeStr = GetXmlNodeNullableValue(item, "ModifyLicense");
        //            ModifyLicense ModifyLicense = repository.ModifyLicense.Items.FirstOrDefault(x => x.IsDeleted != true && x.ShortName == dictTypeStr);
        //            if (unitType != null)
        //            {
        //                unitVM.ModifyLicense = new DictionaryRecordViewModel() { Name = unitType.ShortName, Id = unitType.Id };
        //            }
        //            else
        //            {
        //                throw new Exception(String.Format("Вид лицензируемой продукции задан неверно: {0}", dictTypeStr));
        //            }

        //            //TODO: Addr
        //            xAddr = item.Element("Addr");
        //            unitVM.Address = GetXmlNodeNullableValue(xAddr, "Address");
        //            unitVM.AddressForDocument = GetXmlNodeNullableValue(xAddr, "AddressForDocument", false);
        //        }
        //    }

        //    foreach (var item in xDec.Descendants("PaymentOrder"))
        //    {
        //        PaymentOrderViewModelForDeclaration po = null;
        //        int sysId = GetXmlNodeIntValue(item, "SystemId", false);
        //        if (sysId > 0 && decDB != null)
        //        {
        //            po = result.PaymentOrders.FirstOrDefault(x => x.Id == sysId);
        //        }
        //        if (po == null)
        //        {
        //            po = new PaymentOrderViewModelForDeclaration();
        //        }
        //        po.Nom = GetXmlNodeNullableValue(item, "Number");
        //        po.Date = GetXmlNodeNullableValue(item, "Date");
        //        po.Summ = GetXmlNodeDoubleValue(item, "Sum", true);
        //        po.Comm = GetXmlNodeNullableValue(item, "Comment", false);
        //        po.IsDeleted = item.Element("IsDeleted").Value == "Y";
        //        result.PaymentOrders.Add(po);
        //        //TODO: Загружать сканы PaymentOrder (BlobData)
        //    }
        //    foreach (var item in xDec.Descendants("Attachment"))
        //    {
        //        //TODO: Загружать сканы Attachment (BlobData)
        //    }
        //    return result;
        //}

        public DeclarationViewModel(DeclarationExportFromDatabase dec_exp, IRepository repository)
        {
            if (dec_exp.TypeCreateDeclaration == "List")
            {
                if (dec_exp.company_export != null)
                {
                    CompanyFullNameNow = dec_exp.company_export.company.FullName;
                    CompanyShortNameNow = dec_exp.company_export.company.ShortName;
                    CompanyNameNow = dec_exp.company_export.company.Name;
                }
                LicensedActivityTypeName = dec_exp.licensed_activity_type.ShortName;
                LicensedActivityTypeId = dec_exp.licensed_activity_type.Id;
            }
            TypeCreateDeclaration = dec_exp.TypeCreateDeclaration;
            TagsTable = null;
            if (dec_exp.license != null)
            {
                LicenseId = dec_exp.license.Id;
                LicenseNumber = dec_exp.license.Nom;
                LicenseNomOfBook = dec_exp.license.NomOfBook;
                LicenseDateStart = (dec_exp.declaration != null && dec_exp.declaration.LicenseBaseDateStart.HasValue ? dec_exp.declaration.LicenseBaseDateStart.Value : dec_exp.license.DateStart).ToShortDateString();
                LicenseDateExpired = (dec_exp.declaration != null && dec_exp.declaration.LicenseBaseDateExpired.HasValue ? dec_exp.declaration.LicenseBaseDateExpired.Value : dec_exp.license.DateExpired).ToShortDateString();
            }
            else
            {
                LicenseId = 0;

                LicenseDateStart = "";
                LicenseDateExpired = "";
                if (dec_exp.declaration == null)
                {
                    LicenseNumber = "";
                    LicenseNomOfBook = "";
                }
                else
                {
                    LicenseNumber = dec_exp.declaration.LicenseNom;
                    LicenseNomOfBook = dec_exp.declaration.LicenseNomOfBook;
                }
            }

            //ResolutionType = new DictionaryRecordViewModel() { Id = dec_exp.type_of_resolution.Id, CodeName = dec_exp.type_of_resolution.CodeName, Name = dec_exp.type_of_resolution.ShortName };

            //repository.ReasonForRenew.GetNotDeletedItems().ToList()
            ReasonForRenews = repository.ReasonForRenew.GetNotDeletedItems().Select(x => new DictionaryRecordViewModel() { Id = x.Id, CodeName = x.CodeName, Name = x.ShortName }).ToList();
            if (dec_exp.reason_for_renews != null && dec_exp.reason_for_renews.Count > 0)
            {
                foreach (var item in dec_exp.reason_for_renews)
                {
                    ReasonForRenews.FirstOrDefault(x => x.Id == item.Id).IsChecked = true;
                }
            }

            RefuseBasises = repository.RefuseBasis.GetNotDeletedItems().Select(x => new DictionaryRecordViewModel() { Id = x.Id, CodeName = x.CodeName, Name = x.ShortName }).ToList();
            if (dec_exp.refuse_basis != null && dec_exp.refuse_basis.Count > 0)
            {
                foreach (var item in dec_exp.refuse_basis)
                {
                    RefuseBasises.FirstOrDefault(x => x.Id == item.Id).IsChecked = true;
                }
            }

            if (dec_exp.license_form != null)
            {
                LicenseFormNom = dec_exp.license_form.Nom;
                LicenseFormId = dec_exp.license_form.Id;
            }
            else
            {
                if (dec_exp.declaration == null)
                {
                    LicenseFormNom = "";
                }
                else
                {
                    LicenseFormNom = dec_exp.declaration.LicenseFormNom;
                }
                LicenseFormId = 0;
            }

            if (dec_exp.declaration == null)
            {
                Comm = "";

                ResolutionId = 0;
                ResolutionComm = "";
                RefuseComm = "";
                ResolutionNom = "";
                ResolutionDate = DateTime.Now.ToShortDateString();
                TypeOfType = dec_exp.type_of_type_new.ToString();

                MasterName = "";
                VakeelName = "";
                IsPhoneInformation = true;
                IsPersonGetResult = true;

                UnitsAdd = new List<UnitInDeclarationViewModel>();
                UnitsRemove = new List<UnitInDeclarationViewModel>();
                UnitsEdit = new List<UnitInDeclarationViewModel>();
                UnitsCanceled = new List<UnitInDeclarationViewModel>();
                Status = DeclarationStatus.Draft.ToString();
                Id = 0;
                RegNomAll = "";
                OtherReason = "";
                DateDeclaration = DateTime.Now.ToShortDateString();

                DateTimeDeclaration = DateTime.Now.ToString();

                TimeDeclaration = DateTime.Now.ToShortTimeString();

                IsGrantType = TypeCreateDeclaration == "Grant";
                IsProlongType = TypeCreateDeclaration.Contains("Prolong");
                IsReNewType = TypeCreateDeclaration.Contains("ReNew");
                IsCancelType = TypeCreateDeclaration == "Cancel";
                IsCloneType = TypeCreateDeclaration == "Clone";
                CountYears = 0;

                if (dec_exp.company_export != null)
                {
                    Company = new CompanyViewModel(dec_exp.company_export);
                }
                else
                {
                    Company = new CompanyViewModel();
                }

                StatusRus = "Новый черновик";
            }
            else
            {
                Company = new CompanyViewModel();
                Declaration d = dec_exp.declaration;
                SmevId = d.SmevId;

                PaymentOrdersAll = d.PaymentOrdersAll;

                Comm = d.Comm;

                IsMailGetResult = d.GetResultType.HasFlag(GetResultType.Mail);
                IsEMailGetResult = d.GetResultType.HasFlag(GetResultType.Email);
                IsPersonGetResult = d.GetResultType.HasFlag(GetResultType.Personal);

                IsPhoneInformation = d.GetInformationType.HasFlag(TypeOfGetInformation.Phone);
                IsEmailInformation = d.GetInformationType.HasFlag(TypeOfGetInformation.Email);

                Status = d.Status.ToString();
                UnitsAdd = new List<UnitInDeclarationViewModel>();
                UnitsRemove = new List<UnitInDeclarationViewModel>();
                UnitsEdit = new List<UnitInDeclarationViewModel>();
                UnitsCanceled = new List<UnitInDeclarationViewModel>();
                if (dec_exp.company_export != null)
                {
                    Company.Id = dec_exp.company_export.company.Id;
                }
                else
                {
                    Company.Id = 0;
                }

                Resolution resolution = dec_exp.resolution;
                if (resolution == null)
                {
                    ResolutionId = 0;
                    ResolutionComm = "";
                    RefuseComm = "";
                    ResolutionDate = DateTime.Now.ToShortDateString();
                    TypeOfType = dec_exp.type_of_type_new.ToString();
                    ResolutionTypesAll = "";

                }
                else
                {
                    TypeOfType = resolution.TypeOfType.ToString();
                    ResolutionId = resolution.Id;
                    ResolutionComm = resolution.Comm;
                    RefuseComm = resolution.RefuseComment;
                    ResolutionTypesAll = resolution.TypeOfResolutionsAll;
                    if (dec_exp.TypeCreateDeclaration == "List" && resolution.IsDraft)
                    {
                        ResolutionNom = "";
                        ResolutionDate = "";
                    }
                    else
                    {
                        ResolutionNom = resolution.RegNomAll;
                        //ResolutionDate = d.Status == DeclarationStatus.Agreed || d.Status == DeclarationStatus.Canceled ? resolution.Date.ToShortDateString() : DateTime.Now.ToShortDateString();
                        ResolutionDate = resolution.Date.ToShortDateString();
                    }

                    if (resolution.LicenceApprover == null)
                    {
                        LicenceApprover = new DictionaryRecordViewModel() { Id = 0, Name = "Не определено", CodeName = "PeopleNotChoosen" };
                    }
                    else
                    {
                        LicenceApprover = new DictionaryRecordViewModel() { Id = resolution.LicenceApprover.Id, Name = resolution.LicenceApprover.FIO };
                    }

                    if (resolution.ResolutionCommissionChairman == null)
                    {
                        ResolutionCommissionChairman = new DictionaryRecordViewModel() { Id = 0, Name = "Не определено", CodeName = "PeopleNotChoosen" };
                    }
                    else
                    {
                        ResolutionCommissionChairman = new DictionaryRecordViewModel() { Id = resolution.ResolutionCommissionChairman.Id, Name = resolution.ResolutionCommissionChairman.FIO };
                    }
                }
                MasterName = d.MasterName;
                VakeelName = d.VakeelName;
                StatusRus = DeclarationViewModel.GetRusDeclarationStatus(d.Status);
                IsClosed = d.Status == DeclarationStatus.Agreed || d.Status == DeclarationStatus.Canceled;
                LicenseNomOfBook = d.LicenseNomOfBook;
                OtherReason = d.OtherReason;

                Id = d.Id;
                RegNomAll = d.RegNomAll;

                DateTime dt_update = d.Status == DeclarationStatus.Draft ? DateTime.Now : d.DateDeclaration;

                if (dec_exp.TypeCreateDeclaration == "List" && d.Status == DeclarationStatus.Draft)
                {
                    DateTimeDeclaration = "Соз. " + d.DateTimeCreated.ToString();
                }
                else
                {
                    DateTimeDeclaration = dt_update.ToString();
                }

                DateDeclaration = dt_update.ToShortDateString();
                TimeDeclaration = dt_update.ToShortTimeString();

                IsGrantType = d.Type.HasFlag(DeclarationType.Grant);
                IsProlongType = d.Type.HasFlag(DeclarationType.Prolong);
                IsReNewType = d.Type.HasFlag(DeclarationType.Renew);
                IsCancelType = d.Type.HasFlag(DeclarationType.Cancel);
                IsCloneType = d.Type.HasFlag(DeclarationType.Clone);
                ActionDeclarationRus = DeclarationViewModel.GetRusDeclarationType(d.Type);
                AllTypeDeclarationRus = ActionDeclarationRus;
                if (ReasonForRenews.Where(x => x.IsChecked).Count() > 0)
                {
                    AllTypeDeclarationRus += String.Format(" ({0})", String.Join("; ", ReasonForRenews.Where(x => x.IsChecked).Select(x => x.Name)));
                }

                CountYears = d.CountOfYears;

                DateCreatedStr = d.DateTimeCreated.ToString();
                Creator = d.CreatorName;

                Company.FullName = d.FullNameCompany;
                Company.ShortName = d.ShortNameCompany;
                Company.CompanyName = d.NameCompany;
                Company.INN = d.INN;
                Company.KPP = d.KPP;
                Company.LegalFormType = new DictionaryRecordViewModel() { Name = dec_exp.legal_form_type.ShortName, Id = dec_exp.legal_form_type.Id, FullName = dec_exp.legal_form_type.FullName };
                Company.OGRN = d.OGRN;
                Company.Phone = d.Phone;
                Company.Fax = d.Fax;
                Company.CheckingAccount = d.CheckingAccount;
                Company.BanksName = d.BanksName;

                Company.id_addr = dec_exp.addr == null ? -1 : dec_exp.addr.Id;
                Company.id_postal_addr = dec_exp.postal_addr == null ? -1 : dec_exp.postal_addr.Id;
                Company.Email = d.Email;
                Company.Address = d.ActualAddrStr;
                Company.AddressForDocument = d.AddressForDocument;
                Company.PostalAddress = d.PostalAddrStr;
                Company.PostalCode = d.PostalCode;

                var act_addr_arr = d.ActualAddrAddon.Split(CompanyViewModel.AddressAddonSep);

                Company.AddressHouse = act_addr_arr[0];
                Company.AddressBuildNom = act_addr_arr[1];
                Company.AddressLitera = act_addr_arr[2];
                Company.AddressRoomNom = act_addr_arr[3];
                Company.FSRARAddress = d.FSRARActualAddr;

                var post_addr_arr = d.PostalAddrAddon.Split(CompanyViewModel.AddressAddonSep);

                Company.PostalAddressHouse = post_addr_arr[0];
                Company.PostalAddressBuildNom = post_addr_arr[1];
                Company.PostalAddressLitera = post_addr_arr[2];
                Company.PostalAddressRoomNom = post_addr_arr[3];
                Company.FSRARPostalAddress = d.FSRARPostalAddr;
            }

            Revisions = new List<RevisionViewModel>();
            PaymentOrders = new List<PaymentOrderViewModelForDeclaration>();
            ActionsWithDeclaration = new List<ActionWithDeclarationViewModelForDeclaration>();

            DeclarationsInPack = new List<DeclarationViewModelForPack>();

        }