Example #1
0
        public static string ToString(double value, int precision, string currencySymbol = null, int currencySymbolPosition = 0)
        {
            value = Number.Round(value, precision);
            string ret = Number.ToString(Math.Abs(value), precision);

            if (currencySymbol == null || currencySymbolPosition == 0)
            {
                ConfigurationHolderBase config = BusinessDomain.AppConfiguration;
                currencySymbol         = config.CurrencySymbol;
                currencySymbolPosition = config.CurrencySymbolPosition;
            }

            if (currencySymbol != null && currencySymbolPosition != 0)
            {
                ret = currencySymbolPosition < 0 ?
                      currencySymbol + ret :
                      ret + currencySymbol;
            }

            return(value < 0 ?
                   "-" + ret : ret);
        }
Example #2
0
        protected override void LoadDetails(bool usePriceIn)
        {
            sourceLocationId = locationId;
            sourceLocation   = location;

            if (State == OperationState.Pending)
            {
                targetLocationId = -1;
            }
            else
            {
                Transfer tIn = BusinessDomain.DataAccessProvider.GetOperationById <Transfer> (OperationType.TransferIn, id);
                if (tIn == null)
                {
                    throw new ArgumentException(string.Format("No transfer with the specified ID {0} found.", id));
                }

                targetLocationId = tIn.locationId;
                targetLocation   = tIn.location;
            }

            ConfigurationHolderBase config = BusinessDomain.AppConfiguration;

            details.Clear();
            details.AddRange(BusinessDomain.DataAccessProvider.GetOperationDetailsById <TransferDetail> (OperationType.TransferIn, id, null, null, date, userId, loggedUserId, config.CurrencyPrecision, config.RoundedPrices, usePriceIn));
            List <TransferDetail> detailsOut = BusinessDomain.DataAccessProvider.GetOperationDetailsById <TransferDetail> (OperationType.TransferOut, id, null, sourceLocationId, date, userId, loggedUserId, config.CurrencyPrecision, config.RoundedPrices, usePriceIn).ToList();

            for (int i = details.Count - 1; i >= 0; i--)
            {
                var detail = details [i];
                if (targetLocationId > 0 && detail.LocationId != targetLocationId)
                {
                    details.RemoveAt(i);
                    continue;
                }

                var matches = detailsOut.Where(d =>
                                               d.ItemId == detail.ItemId &&
                                               d.LotId == detail.LotId &&
                                               d.Quantity.IsEqualTo(detail.Quantity) &&
                                               d.PriceIn.IsEqualTo(detail.PriceIn) &&
                                               d.PriceOut.IsEqualTo(detail.PriceOut)).ToList();

                // Find the matching out detail with the closest timestamp
                TransferDetail matchingOut = null;
                double         minDiff     = double.MaxValue;

                for (int j = matches.Count - 1; j >= 0; j--)
                {
                    TransferDetail thisMatch = matches [j];
                    double         diff      = Math.Abs((thisMatch.TimeStamp - detail.TimeStamp).TotalMilliseconds);

                    if (matchingOut == null)
                    {
                        matchingOut = thisMatch;
                        minDiff     = diff;
                        continue;
                    }

                    if (diff < minDiff)
                    {
                        matchingOut = thisMatch;
                        minDiff     = diff;
                    }
                }

                if (matchingOut == null)
                {
                    details.RemoveAt(i);
                    continue;
                }

                // Remove the match from next searches
                detailsOut.Remove(matchingOut);

                referenceDocumentId   = detail.ReferenceDocumentId;
                detail.TargetDetailId = detail.DetailId;
                detail.SourceDetailId = matchingOut.DetailId;
                detail.IsDirty        = false;

                if (targetLocationId < 0)
                {
                    targetLocationId = detail.LocationId;
                    targetLocation   = Entities.Location.Cache.GetById(targetLocationId).Name;
                }
            }

            if (details.Count == 0)
            {
                throw new ArgumentException(string.Format("No matching transfer details for transfer with the specified ID {0} found.", id));
            }
        }