Esempio n. 1
0
        public void GetAmount_StandardMeasureToKmph_Factor3point6Larger()
        {
            var expected = AmountConverter.ToAmountType(iValue: 90.0f);
            var velocity = new Velocity(amount: 25.0f);
            var un       = new ConstantConverterUnit <Velocity>("km\\h", Factors.Kilo / Factors.SecondsPerHour);
            var actual   = velocity.GetAmount(un);

            AmountAssert.AreEqual(expected, actual);
        }
        public void Should_Convert()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "0.02",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("20000000000000000");
        }
        public void Should_Convert_With_Both_Peices()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "1000.0001",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("1000000100000000000000");
        }
        public void Should_Convert_Minimum_Of_One_Wei()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "0.000000000000000001",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("1");
        }
        public void Should_Convert_With_Only_Decimal_Portion_And_Leading_Zeros()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = ".0001",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("100000000000000");
        }
        public void Should_Convert_From_ETH_Wei_With_Only_Decimal_Portion()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = ".1",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("100000000000000000");
        }
        public void Should_Throw_If_Not_Numeric()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "A",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            Should.Throw <ValidationException>(() => balanceFormater.GetNativeAmount(getNativeAmountRequest));
        }
        public void Should_Work_With_All_Zeros()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "0000.000000",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("0");
        }
        public void Should_Truncate_Decimal_If_Below_Granularity()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "1000.0000000000000000001",
                Granularity      = 18,
                DecimalSeperator = '.'
            };

            balanceFormater.GetNativeAmount(getNativeAmountRequest).ShouldBe("1000000000000000000000");
        }
Esempio n. 10
0
        public void Should_Prefix_Zero()
        {
            var balanceFormater        = new AmountConverter();
            var balanceFormaterRequest = new FormatAmountRequest
            {
                Amount                 = "0123",
                Granularity            = 5,
                DecimalPlacesToDisplay = 4,
                DecimalSeperator       = '.'
            };

            balanceFormater.GetFormatedAmount(balanceFormaterRequest).ShouldBe("0.0012");
        }
Esempio n. 11
0
        public void Should_Handle_Null_Amount()
        {
            var balanceFormater        = new AmountConverter();
            var balanceFormaterRequest = new FormatAmountRequest
            {
                Amount                 = null,
                Granularity            = 5,
                DecimalPlacesToDisplay = 4,
                DecimalSeperator       = '.'
            };

            balanceFormater.GetFormatedAmount(balanceFormaterRequest).ShouldBe("0.0000");
        }
Esempio n. 12
0
        public void Should_Handle_Negative_Amount()
        {
            var balanceFormater        = new AmountConverter();
            var balanceFormaterRequest = new FormatAmountRequest
            {
                Amount                 = "-9979261128182853278",
                Granularity            = 18,
                DecimalPlacesToDisplay = 4,
                DecimalSeperator       = '.'
            };

            balanceFormater.GetFormatedAmount(balanceFormaterRequest).ShouldBe("-9.9792");
        }
        public void Should_Throw_If_DecimalSeperator_Default()
        {
            var balanceFormater        = new AmountConverter();
            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = "0000.000000",
                Granularity      = 18,
                DecimalSeperator = '\0'
            };

            Should.Throw <ValidationException>(() => balanceFormater.GetNativeAmount(getNativeAmountRequest));
            ;
        }
Esempio n. 14
0
        public void Should_Display_Proper_Decimals()
        {
            var balanceFormater        = new AmountConverter();
            var balanceFormaterRequest = new FormatAmountRequest
            {
                Amount                 = "9979261128182853278",
                Granularity            = 18,
                DecimalPlacesToDisplay = 3,
                DecimalSeperator       = '.'
            };

            balanceFormater.GetFormatedAmount(balanceFormaterRequest).ShouldBe("9.979");
        }
Esempio n. 15
0
        public void Should_Handle_Negative_Decimal_Amount_2()
        {
            var balanceFormater        = new AmountConverter();
            var balanceFormaterRequest = new FormatAmountRequest
            {
                Amount                 = "-342344534500000000",
                Granularity            = 18,
                DecimalPlacesToDisplay = 4,
                DecimalSeperator       = '.'
            };

            balanceFormater.GetFormatedAmount(balanceFormaterRequest).ShouldBe("-0.3423");
        }
        public void ConvertToWord_Input_VeryLarge()
        {
            decimal           amount            = 12312345645678978956712345671.06M;
            OverflowException expectedExcetpion = null;

            try
            {
                AmountConverter.ToWords(amount);
            }
            catch (OverflowException ex)
            {
                expectedExcetpion = ex;
            }

            Assert.IsNotNull(expectedExcetpion);
        }
Esempio n. 17
0
        private string ProcessNumber(decimal number)
        {
            if (number < 0)
            {
                throw new ArgumentException("The number should be positive.");
            }
            AmountConverter converter = new AmountConverter();
            ulong           integer   = (ulong)Truncate(number);           // extracts the integer part of the number
            ulong           decimals  = (ulong)((number - integer) * 100); // extracts the decimals of the number and converts it to integer


            string result =
                ($"{converter.Convert(integer)} dollar{(integer > 1 ? "s" : "")}" +
                 $"{(decimals > 0 ? $" and {converter.Convert(decimals)} cent{(decimals > 1 ? "s" : "")}" : "")}");

            return(result);
        }
Esempio n. 18
0
        public IActionResult Get(decimal number)
        {
            try
            {
                string words = string.Empty;
                if (number > 0)
                {
                    words = AmountConverter.ToWords(number);
                }

                return(Ok(words));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        public override IEnumerable <ValidationError> Validate(PropertyInfo property, object value)
        {
            IList <ValidationError> retval = null;

            retval = new List <ValidationError>();

            if (!string.IsNullOrEmpty((string)value))
            {
                try
                {
                    AmountConverter.Convert((string)value, GetAttribute().GreaterThanZero);
                }
                catch (AmountConvertionException e)
                {
                    retval.Add(new AmountValidationError(e.Reason));
                }
            }

            return(retval);
        }
        protected async Task Send()
        {
            Console.WriteLine("Sending SendAction");

            var getNativeAmountRequest = new GetNativeAmountRequest
            {
                Amount           = Amount,
                DecimalSeperator = '.',
                Granularity      = 18
            };
            string nativeAmount = AmountConverter.GetNativeAmount(getNativeAmountRequest);
            await Mediator.Send(new SendAction
            {
                EdgeCurrencyWalletId = EdgeCurrencyWalletId,
                NativeAmount         = nativeAmount,
                DestinationAddress   = DestinationAddress,
                CurrencyCode         = CurrencyCode,
                Fee = Fee
            });

            await Mediator.Send(new ChangeRouteRequest { NewRoute = WalletPageModel.Route });
        }
Esempio n. 21
0
        public void Action(EditItemInput message)
        {
            CheckItemInput(message);
            ItemModel modelItem   = null;
            Item      updatedItem = null;

            if (message is EditGuestInput)
            {
                decimal amount = AmountConverter.Convert(message.Amount, false);
                modelItem   = CurrentEvent.Guests.Single(x => x.Id == message.ItemId);
                updatedItem = EventService.UpdateGuest(CurrentEvent.Id, modelItem.Id, message.Name, amount);
                modelItem.Map(updatedItem);
                Queue(ToItemOutput(modelItem, ItemType.Guest));
            }
            else if (message is EditExpenseInput)
            {
                decimal amount = AmountConverter.Convert(message.Amount, false);
                modelItem   = CurrentEvent.Expenses.Single(x => x.Id == message.ItemId);
                updatedItem = EventService.UpdateExpense(CurrentEvent.Id, modelItem.Id, message.Name, amount);
                modelItem.Map(updatedItem);
                Queue(ToItemOutput(modelItem, ItemType.Expense));
            }
            else
            {
                throw new InvalidCastException($"{message.GetType().Name} is not handled");
            }

            if (modelItem != null)
            {
                CalculateOutcome();
                QueueItemsCount();
                QueueItemsAmount();
                QueueOutcomeAvailable();
                QueueOutcomeSummary();
                QueueOutcomeGuests();
                QueueItemSaved();
            }
        }
Esempio n. 22
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     AmountConverter.Clear();
     FromConverter.SelectedIndex = 23;
     ToConverter.SelectedIndex   = 0;
 }
Esempio n. 23
0
        /// <summary>
        /// Handles the creation of a manual document matching
        /// </summary>
        /// <param name="request">request</param>
        /// <param name="cancellationToken">cancellationToken</param>
        public async Task <ManualDocumentMatchingRecord> Handle(CreateManualDocumentMatchingCommand request, CancellationToken cancellationToken)
        {
            _unitOfWork.BeginTransaction();
            try
            {
                var manualDocumentMatchingRecord = _mapper.Map <ManualDocumentMatchingRecord>(request);

                var matchableDocumentIds = new List <MatchableSourceIdDto>();

                // Getting the information for the documents that we want to match
                // We get mostly the rates of exchange which have been fixed during the posting of these documents
                foreach (var document in manualDocumentMatchingRecord.DocumentMatchings)
                {
                    matchableDocumentIds.Add(new MatchableSourceIdDto()
                    {
                        SourceCashLineId = document.SourceCashLineId, SourceInvoiceId = document.SourceInvoiceId, SourceJournalLineId = document.SourceJournalLineId
                    });
                }

                var matchableDocumentsSummaryInformation = await _manualDocumentMatchingQueries.GetMatchableDocumentsSummaryInformation(
                    request.Company,
                    matchableDocumentIds);

                // Rebuilding a complete list of records to be pushed as a parameter of the "create match" SP
                List <DocumentMatching> documentMatchingRecords = new List <DocumentMatching>();
                foreach (var documentMatchingRecord in manualDocumentMatchingRecord.DocumentMatchings)
                {
                    DocumentMatching documentMatching = new DocumentMatching();
                    documentMatching.TransactionDocumentId = documentMatchingRecord.TransactionDocumentId;

                    // There is a complete mismatch into the names used in the exchange with the
                    // app (documentmatching.Amount is the full document amount), and the one
                    // understood by the DB (documentmatching.Amount is the amount matched in the doc matching)
                    // The right solution should be to use different classes...
                    documentMatching.Amount = documentMatchingRecord.DocumentAmount;

                    var matchableDocumentSummaryInformation = matchableDocumentsSummaryInformation
                                                              .Where(d => d.TransactionDocumentId == documentMatchingRecord.TransactionDocumentId).FirstOrDefault();
                    switch ((MasterDocumentType)matchableDocumentSummaryInformation.TransactionDocumentTypeId)
                    {
                    case MasterDocumentType.PI:
                    case MasterDocumentType.CN:
                    case MasterDocumentType.CP:
                        documentMatching.TransactionDirectionId = (int)TransactionDirection.Pay;
                        break;

                    case MasterDocumentType.SI:
                    case MasterDocumentType.DN:
                    case MasterDocumentType.CI:
                        documentMatching.TransactionDirectionId = (int)TransactionDirection.Recieve;
                        break;

                    case MasterDocumentType.JL:
                        documentMatching.TransactionDirectionId = documentMatching.DocumentAmount > 0 ?
                                                                  (int)TransactionDirection.Pay : (int)TransactionDirection.Recieve;
                        break;

                    default:
                        // We should not be there...
                        break;
                    }

                    switch ((MasterDocumentType)matchableDocumentSummaryInformation.TransactionDocumentTypeId)
                    {
                    case MasterDocumentType.PI:
                    case MasterDocumentType.CN:
                    case MasterDocumentType.CI:
                        documentMatching.SigningFactor = -1;
                        break;

                    case MasterDocumentType.CP:
                    case MasterDocumentType.SI:
                    case MasterDocumentType.DN:
                    case MasterDocumentType.JL:
                        documentMatching.SigningFactor = 1;
                        break;
                    }

                    documentMatching.TransactionDocumentTypeId = documentMatchingRecord.TransactionDocumentTypeId;
                    documentMatching.DepartmentId = documentMatchingRecord.DepartmentId;
                    documentMatching.DocumentDate = documentMatchingRecord.DocumentDate;
                    decimal?matchedAmount = documentMatching.Amount;

                    // Calculation of the statutory / fct ccy amounts for the document matching
                    if (matchedAmount == matchableDocumentSummaryInformation.UnmatchedAmount)
                    {
                        // In the case we are fully matching the document, we set the statutory & functional matched amounts
                        // to the value of the remaining unmatched amount. This way, we are sure that, in the case a document has
                        // multiple matchings, the sum of the matched amounts in statutory & fct ccies are = to the total amount
                        // in these ccies
                        documentMatching.StatutoryCcyAmount  = matchableDocumentSummaryInformation.UnmatchedAmountInStatutoryCurrency;
                        documentMatching.FunctionalCcyAmount = matchableDocumentSummaryInformation.UnmatchedAmountInFunctionalCurrency;
                    }
                    else
                    {
                        // We are not fully matching the matchable document.
                        // Calculate the statutory & functional currencies based on the rate of exchange stored
                        // in the transaction document which is matched, at the time of its posting
                        // NOTE THAT the unmatched ccies will be updated by a SP called when saving the document matching
                        documentMatching.StatutoryCcyAmount = AmountConverter.ConvertAmountThroughIntermediateRoeToUSD(
                            documentMatching.Amount.Value,
                            matchableDocumentSummaryInformation.RoeDocumentCurrency,
                            matchableDocumentSummaryInformation.RoeDocumentCurrencyType,
                            matchableDocumentSummaryInformation.RoeStatutoryCurrency,
                            matchableDocumentSummaryInformation.RoeStatutoryCurrencyType,
                            2);
                        documentMatching.FunctionalCcyAmount = AmountConverter.ConvertAmountThroughIntermediateRoeToUSD(
                            documentMatching.Amount.Value,
                            matchableDocumentSummaryInformation.RoeDocumentCurrency,
                            matchableDocumentSummaryInformation.RoeDocumentCurrencyType,
                            matchableDocumentSummaryInformation.RoeFunctionalCurrency,
                            matchableDocumentSummaryInformation.RoeFunctionalCurrencyType,
                            2);
                    }

                    documentMatching.IsCreditOrDebit = documentMatchingRecord.IsCreditOrDebit;
                    if (documentMatchingRecord.LineId == 0)
                    {
                        documentMatching.LineId = null;
                    }
                    else
                    {
                        documentMatching.LineId = documentMatchingRecord.LineId;
                    }

                    documentMatching.Credit              = documentMatchingRecord.Credit;
                    documentMatching.Debit               = documentMatchingRecord.Debit;
                    documentMatching.SourceCashLineId    = documentMatchingRecord.SourceCashLineId == 0 ? null : documentMatchingRecord.SourceCashLineId;
                    documentMatching.SourceInvoiceId     = documentMatchingRecord.SourceInvoiceId == 0 ? null : documentMatchingRecord.SourceInvoiceId;
                    documentMatching.SourceJournalLineId = documentMatchingRecord.SourceJournalLineId == 0 ? null : documentMatchingRecord.SourceJournalLineId;
                    documentMatchingRecords.Add(documentMatching);
                }

                // Saving the matchflag in the database
                manualDocumentMatchingRecord.DocumentMatchings = documentMatchingRecords;
                var matchingRecord = await _manualDocumentMatchingRepository.CreateUpdateDocumentMatching(manualDocumentMatchingRecord);

                manualDocumentMatchingRecord.MatchFlagCode = matchingRecord.MatchFlagCode;
                manualDocumentMatchingRecord.MatchFlagId   = matchingRecord.MatchFlagId;

                // Calculating the sums of the fct & statut ccy amounts for all the documents, to check if they are = 0 or not
                // This will determine the need for a reval record
                var sumsByDepartmentAndDirection = documentMatchingRecords.GroupBy(d => new { d.DepartmentId, d.TransactionDirectionId })
                                                   .Select(g => new
                {
                    g.Key.DepartmentId,
                    g.Key.TransactionDirectionId,
                    Amount = g.Sum(s => s.Amount * s.SigningFactor),
                    FunctionalCcyAmount = g.Sum(s => s.FunctionalCcyAmount * s.SigningFactor),
                    StatutoryCcyAmount  = g.Sum(s => s.StatutoryCcyAmount * s.SigningFactor),
                }).ToList();

                if (sumsByDepartmentAndDirection.Any(sum => sum.FunctionalCcyAmount != 0 || sum.StatutoryCcyAmount != 0))
                {
                    // Need to create a reval document
                    // Note that reval documents are created (for cash by picking) at posting time of the cbp
                    var revaluationInformation = await _transactionDocumentRepository.CreateRevaluation(
                        request.Company,
                        null,
                        request.CurrencyCode,
                        matchingRecord.MatchFlagId.Value,
                        request.PaymentDocumentDate,
                        request.PaymentDocumentDate,
                        request.PaymentDocumentDate);
                    await EnqueueMessageForAccountingDocumentCreation(revaluationInformation.TransactionDocumentId, request.Company);

                    manualDocumentMatchingRecord.ReversalRevalJournalCode = revaluationInformation.DocumentReference;
                }

                _unitOfWork.Commit();
                _logger.LogInformation("Document match created with match id {Atlas.MatchFlagId}.", manualDocumentMatchingRecord.MatchFlagId.Value);
                return(manualDocumentMatchingRecord);
            }
            catch
            {
                _unitOfWork.Rollback();
                throw;
            }
        }
Esempio n. 24
0
 public FormDataClass(AmountConverter aAmountConverter)
 {
     _Amount         = "";
     SendAction      = new SendAction();
     AmountConverter = aAmountConverter;
 }