Exemplo n.º 1
0
        public virtual bool HasSellerSignatoryInfo(Docflow.IAccountingDocumentBase document)
        {
            if (document.IsFormalized != true)
            {
                return(false);
            }

            using (var body = document.Versions.Single(v => v.Id == document.SellerTitleId).Body.Read())
            {
                return(FormalizeDocumentsParser.SellerSignatoryInfo.HasSellerSignatoryInfo(body));
            }
        }
Exemplo n.º 2
0
        public static bool HasUnsignedSellerTitle(Docflow.IAccountingDocumentBase statement)
        {
            if (statement.SellerTitleId != null)
            {
                var existingSellerTitle = statement.Versions.Where(x => x.Id == statement.SellerTitleId).FirstOrDefault();
                if (existingSellerTitle != null && !Signatures.Get(existingSellerTitle).Any())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public virtual bool HasSellerTitleInfo(Docflow.IAccountingDocumentBase document)
        {
            if (document.IsFormalized != true)
            {
                return(false);
            }

            using (var body = document.Versions.Single(v => v.Id == document.SellerTitleId).Body.Read())
            {
                using (var memory = new System.IO.MemoryStream())
                {
                    body.CopyTo(memory);
                    return(FormalizeDocumentsParser.SellerTitleInfo.HasRequiredProperties(memory.ToArray()));
                }
            }
        }
Exemplo n.º 4
0
        public virtual void AddOrReplaceSellerTitleInfo(Docflow.IAccountingDocumentBase document)
        {
            if (document == null || !document.HasVersions)
            {
                return;
            }

            var version = document.Versions.SingleOrDefault(v => v.Id == document.SellerTitleId);

            if (version == null)
            {
                return;
            }

            using (var memory = new System.IO.MemoryStream())
            {
                version.Body.Read().CopyTo(memory);
                var newBody = AddOrReplaceSellerTitleInfo(memory, document.BusinessUnitBox, document.Counterparty,
                                                          document.FormalizedServiceType.Value, document.IsAdjustment == true);
                version.Body.Write(newBody);
                document.Save();
            }
        }
Exemplo n.º 5
0
        public static void GenerateSellerTitle(Docflow.IAccountingDocumentBase statement, Docflow.Structures.AccountingDocumentBase.ISellerTitle sellerTitle)
        {
            if (statement.IsFormalized != true)
            {
                return;
            }

            var sellerSignatoryInfo = new FormalizeDocumentsParser.SellerSignatoryInfo();

            sellerSignatoryInfo.CompanyName = statement.BusinessUnit.LegalName;
            sellerSignatoryInfo.FirstName   = sellerTitle.Signatory.Person.FirstName;
            sellerSignatoryInfo.LastName    = sellerTitle.Signatory.Person.LastName;
            sellerSignatoryInfo.MiddleName  = sellerTitle.Signatory.Person.MiddleName;
            sellerSignatoryInfo.JobTitle    = sellerTitle.Signatory.JobTitle != null ? sellerTitle.Signatory.JobTitle.Name : null;

            // Лицо, совершившее сделку и ответственное за ее оформление.
            if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_DealAndRegister)
            {
                sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.MadeAndSignOperation;
            }
            // Лицо, ответственное за оформление свершившегося события.
            else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_Register)
            {
                sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.PersonDocumentedOperation;
            }
            // Лицо, совершившее сделку и операцию, ответственное за ее оформление и за подписание счетов-фактур.
            else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_DealAndRegisterAndInvoiceSignatory)
            {
                sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.MadeAndResponsibleForOperationAndSignedInvoice;
            }
            // Лицо, ответственное за оформление свершившегося события и за подписание счетов-фактур.
            else if (sellerTitle.SignatoryPowers == Docflow.AccountingDocumentBases.Resources.PropertiesFillingDialog_HasAuthority_RegisterAndInvoiceSignatory)
            {
                sellerSignatoryInfo.Powers = Constants.Module.SellerTitlePowers.ResponsibleForOperationAndSignatoryForInvoice;
            }

            if (sellerTitle.SignatoryPowerOfAttorney != null)
            {
                sellerSignatoryInfo.PowersBase = Docflow.SignatureSettings.Info.Properties.Reason.GetLocalizedValue(Docflow.SignatureSetting.Reason.PowerOfAttorney);
                if (!string.IsNullOrWhiteSpace(sellerTitle.SignatoryPowerOfAttorney.RegistrationNumber))
                {
                    sellerSignatoryInfo.PowersBase += Docflow.OfficialDocuments.Resources.Number + sellerTitle.SignatoryPowerOfAttorney.RegistrationNumber;
                }

                if (sellerTitle.SignatoryPowerOfAttorney.RegistrationDate != null)
                {
                    sellerSignatoryInfo.PowersBase += Docflow.OfficialDocuments.Resources.DateFrom + sellerTitle.SignatoryPowerOfAttorney.RegistrationDate.Value.ToString("d");
                }
            }
            else if (!string.IsNullOrWhiteSpace(sellerTitle.SignatoryOtherReason))
            {
                sellerSignatoryInfo.PowersBase = sellerTitle.SignatoryOtherReason;
            }
            else
            {
                sellerSignatoryInfo.PowersBase = Docflow.SignatureSettings.Info.Properties.Reason.GetLocalizedValue(Docflow.SignatureSetting.Reason.Duties);
            }

            sellerSignatoryInfo.TIN = statement.BusinessUnit.TIN;

            using (var body = statement.Versions.Single(v => v.Id == statement.SellerTitleId).Body.Read())
            {
                using (var patchedXml = sellerSignatoryInfo.AddOrReplaceToXml(body))
                {
                    if (!HasUnsignedSellerTitle(statement))
                    {
                        // При создании версии чистится статус эл. обмена, восстанавливаем его.
                        var exchangeState = statement.ExchangeState;
                        statement.CreateVersion();
                        statement.ExchangeState = exchangeState;
                    }

                    var version = statement.LastVersion;
                    statement.SellerTitleId = version.Id;
                    version.Body.Write(patchedXml);
                    statement.IsFormalizedSignatoryEmpty = false;
                    statement.Save();
                }
            }
        }
Exemplo n.º 6
0
        private static void FillBusinessUnitAndCounterparty(Docflow.IAccountingDocumentBase document,
                                                            FormalizeDocumentsParser.ISellerTitle sellerTitle,
                                                            bool requireFtsId)
        {
            ExchangeCore.IBusinessUnitBox box          = null;
            Parties.ICounterparty         counterparty = null;

            // Поиск по ФНС ИД.
            if (!string.IsNullOrWhiteSpace(sellerTitle.SenderId) || !string.IsNullOrWhiteSpace(sellerTitle.ReceiverId))
            {
                var exchangeProvider = GetExchangeService(sellerTitle);
                var boxes            = ExchangeCore.BusinessUnitBoxes.GetAll()
                                       .Where(b => b.ExchangeService.ExchangeProvider == exchangeProvider)
                                       .ToList();

                box = boxes.Where(b => b.FtsId == sellerTitle.SenderId).SingleOrDefault();
                if (box != null)
                {
                    counterparty = GetCounterparty(sellerTitle.ReceiverId, box);
                }
            }

            // Поиск по ИНН \ КПП.
            if (!requireFtsId && (box == null || counterparty == null))
            {
                var boxOnTin = GetBox(sellerTitle.Seller);
                if (boxOnTin != null)
                {
                    if (counterparty == null)
                    {
                        counterparty = GetCounterparty(sellerTitle.Buyer, boxOnTin, true);
                    }
                    if (box == null)
                    {
                        box = boxOnTin;
                    }
                }
            }

            // Если нашелся ящик - заполняем.
            if (box != null)
            {
                document.BusinessUnitBox = box;
                document.BusinessUnit    = box.BusinessUnit;
                document.Counterparty    = counterparty;
            }

            if (!requireFtsId && (box == null || counterparty == null))
            {
                // Ищем по ИНН \ КПП, не связываясь с МКДО.
                var unit = GetBusinessUnit(sellerTitle.Seller);
                if (unit != null)
                {
                    if (document.Counterparty == null)
                    {
                        document.Counterparty = GetCounterparty(sellerTitle.Buyer, null, false);
                    }
                    if (document.BusinessUnit == null)
                    {
                        document.BusinessUnit = unit;
                    }
                }
            }
        }