public static string TotalAmountInCurrencyToWords(IContractualDocument contractualDocument)
        {
            if (contractualDocument.TotalAmount == null || contractualDocument.Currency == null)
            {
                return(null);
            }

            var totalAmount    = contractualDocument.TotalAmount.Value;
            var integerPart    = (long)Math.Truncate(totalAmount);
            var fractionalPart = (int)Math.Round((totalAmount - integerPart) * 100);

            var contractCurrencyShortName = contractualDocument.Currency.ShortName.Trim();
            var currencyName = contractCurrencyShortName.EndsWith(Constants.ContractualDocument.ShortNameEnd) ?
                               contractCurrencyShortName :
                               StringUtils.NumberDeclension(integerPart,
                                                            contractCurrencyShortName,
                                                            Sungero.Core.CaseConverter.ConvertCurrencyNameToTargetDeclension(contractCurrencyShortName, DeclensionCase.Genitive),
                                                            Sungero.Core.CaseConverter.ConvertCurrencyNameToTargetDeclension(contractCurrencyShortName.Pluralize(), DeclensionCase.Genitive));

            var contractCurrencyFractionName = contractualDocument.Currency.FractionName.Trim();
            var currencyFractionalName       = contractCurrencyFractionName.EndsWith(Constants.ContractualDocument.ShortNameEnd) ?
                                               contractCurrencyFractionName :
                                               StringUtils.NumberDeclension(fractionalPart,
                                                                            contractCurrencyFractionName,
                                                                            Sungero.Core.CaseConverter.ConvertCurrencyNameToTargetDeclension(contractCurrencyFractionName, DeclensionCase.Genitive),
                                                                            Sungero.Core.CaseConverter.ConvertCurrencyNameToTargetDeclension(contractCurrencyFractionName.Pluralize(), DeclensionCase.Genitive));

            return(string.Format("{0},{1} {2} ({3} {2} {1} {4})",
                                 integerPart.ToString("N0"), fractionalPart.ToString("D2"), currencyName,
                                 StringUtils.NumberToWords(integerPart).Capitalize(), currencyFractionalName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Получить данные договора для формирования имени доп.согл и акта.
        /// </summary>
        /// <param name="contract">Документ.</param>
        /// <returns>Данные документа.</returns>
        /// <remarks>Если нет прав на договор, то возникнет исключение.</remarks>
        public static string GetNamePartByContract(IContractualDocument contract)
        {
            var namePart = ContractBases.Resources.NamePartForLeadDocument + contract.DocumentKind.ShortName.ToLower();

            if (!string.IsNullOrWhiteSpace(contract.RegistrationNumber))
            {
                namePart += OfficialDocuments.Resources.Number + contract.RegistrationNumber;
            }
            if (contract.Counterparty != null)
            {
                namePart += ContractBases.Resources.NamePartForContractor + contract.Counterparty.DisplayValue;
            }
            return(namePart);
        }