Exemple #1
0
        public Task SetPriceFromItem(ProjectJournalLineClient orderLine, InvItem item)
        {
            Task t  = _SetPriceFromItem(orderLine, item, 0d, 0d);
            Task t2 = null;

            if (this.UseCustomerPrices && this._PriceList != null && orderLine._Item != null)
            {
                t2 = GetCustomerPrice(orderLine, true);
            }
            if (t2 == null)
            {
                return(t);
            }
            else if (t == null)
            {
                return(t2);
            }
            else if (t.IsCompleted)
            {
                return(t2);
            }
            else if (t2.IsCompleted)
            {
                return(t);
            }
            else
#if !SILVERLIGHT
            { return(Task.WhenAll(new Task[] { t, t2 })); }
#else
            { return(t2); }
#endif
        }
        void OpenImportDataPage(ProjectJournalClient selectedItem)
        {
            var projectJournalLine = new ProjectJournalLineClient();

            projectJournalLine.SetMaster(selectedItem);
            string header          = selectedItem._Journal;
            var    baseEntityArray = new UnicontaBaseEntity[] { projectJournalLine, selectedItem };

            AddDockItem(TabControls.ImportPage, new object[] { baseEntityArray, header }, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Import"), header));
        }
 private void Initialize(UnicontaBaseEntity[] simulatedTransactions)
 {
     InitializeComponent();
     dgSimulatedPrjJrnllLinePageGrid.api = api;
     if (simulatedTransactions != null && simulatedTransactions.Length > 0)
     {
         var lst = new ProjectJournalLineClient[simulatedTransactions.Length];
         int i   = 0;
         foreach (var t in (IEnumerable <ProjectJournalLineClient>)simulatedTransactions)
         {
             lst[i++] = t;
         }
         dgSimulatedPrjJrnllLinePageGrid.ClearSorting();
         dgSimulatedPrjJrnllLinePageGrid.SetSource(lst);
     }
     SetRibbonControl(localMenu, dgSimulatedPrjJrnllLinePageGrid);
     dgSimulatedPrjJrnllLinePageGrid.BusyIndicator = busyIndicator;
     localMenu.OnItemClicked += gridRibbon_BaseActions;
 }
Exemple #4
0
        private async Task LookRate(ProjectJournalLineClient rec, double price, byte From, byte To)
        {
            var Rate = await api.session.ExchangeRate((Currencies)From, (Currencies)To, DateTime.Now, api.CompanyEntity);

            rec.SalesPrice = (Rate == 0d) ? price : Math.Round(price * Rate, 2);
        }
Exemple #5
0
        Task _SetPriceFromItem(ProjectJournalLineClient orderLine, InvItem item, double LineMarginRatio, double LineSalesCharge)
        {
            Task t             = null;
            byte priceCurrency = item._Currency1;
            var  price         = item._SalesPrice1;
            var  costprice     = item._CostPrice;

            var MarginRatio = this.MarginRatio;

            if (LineMarginRatio > 0d)
            {
                MarginRatio = LineMarginRatio;
            }

            if (MarginRatio > 0d && MarginRatio < 100d)
            {
                priceCurrency = 0;
                var margin = costprice * MarginRatio / (100d - MarginRatio);
                price = Math.Round(costprice + margin, RoundMargin ? 0 : 2) + SalesCharge + LineSalesCharge;
            }
            else
            {
                var pg = this.PriceGrp;
                if (pg == 0)
                {
                    if (OrderCurrency == item._Currency2)
                    {
                        pg = 2;
                    }
                    else if (OrderCurrency == item._Currency3)
                    {
                        pg = 3;
                    }
                }
                if (pg == 2)
                {
                    priceCurrency = item._Currency2;
                    price         = item._SalesPrice2;
                }
                else if (pg == 3)
                {
                    priceCurrency = item._Currency3;
                    price         = item._SalesPrice3;
                }
            }

            if (OrderCurrency != priceCurrency)
            {
                if (priceCurrency == 0)
                {
                    priceCurrency = CompCurrency;
                }

                if (OrderCurrency != priceCurrency)
                {
                    if (priceCurrency == CompCurrency)
                    {
                        price = (ExchangeRate == 0d) ? price : Math.Round(price * ExchangeRate, 2);
                    }
                    else
                    {
                        t     = LookRate(orderLine, price, priceCurrency, OrderCurrency);
                        price = 0;
                    }
                }
            }
            orderLine.CostPrice = item._CostPrice;
            if (price != 0)
            {
                orderLine.SalesPrice = price;
            }
            return(t);
        }
Exemple #6
0
        public async Task GetCustomerPrice(ProjectJournalLineClient orderLine, bool IsNewItem)
        {
            if (!this.UseCustomerPrices)
            {
                return;
            }

            var t = LoadingTask;

            if (t != null && !t.IsCompleted)
            {
                await t;
            }

            if (this._PriceList == null || orderLine._Item == null)
            {
                return;
            }
            var itemRec = (InvItem)items.Get(orderLine._Item);

            if (itemRec == null)
            {
                return;
            }
            orderLine._Qty = Math.Round(orderLine._Qty, itemRec._Decimals);

            if (CustomerPrices == null)
            {
                await loadPriceList();
            }
            if (CustomerPrices == null)
            {
                return;
            }

            var len       = CustomerPrices.Length;
            var searchrec = new InvPriceListLine();

            searchrec._DCType = debtor.__DCType();
            searchrec._Item   = orderLine._Item;
            // Do not include Variant, since we also want to finde prices without variant
            //searchrec._Variant1 = orderLine._Variant1;
            //searchrec._Variant2 = orderLine._Variant2;
            searchrec._prioritet = int.MinValue;
            var pos = search(searchrec);

            var              now             = OrderTime;
            int              FoundPriority   = -1;
            bool             HasQtyPrices    = false;
            int              CurVariantMatch = -1;
            InvPriceListLine rec             = null;
            var              qty             = Math.Abs(orderLine._Qty) + 0.00000000001d;

            while (pos < len)
            {
                var r = CustomerPrices[pos++];
                var c = string.Compare(r._Item, orderLine._Item);
                if (c != 0)
                {
                    break;
                }
                if ((r._ValidFrom != DateTime.MinValue && now < r._ValidFrom) ||
                    (r._ValidTo != DateTime.MinValue && now > r._ValidTo))
                {
                    continue;
                }
                int VariantMatch = VariantCompare(orderLine._Variant1, r._Variant1);
                if (VariantMatch >= 0)
                {
                    int VariantMatch2 = VariantCompare(orderLine._Variant2, r._Variant2);
                    if (VariantMatch2 >= 0)
                    {
                        VariantMatch += VariantMatch2;
                        if (VariantMatch >= CurVariantMatch)
                        {
                            if (r._Qty != 0d)
                            {
                                HasQtyPrices = true;
                            }
                            if (r._Qty <= qty)
                            {
                                bool UseMatch = true;
                                if (r._FirstMatch)
                                {
                                    if (FoundPriority == -1)
                                    {
                                        FoundPriority = r._prioritet;
                                    }
                                    else if (FoundPriority != r._prioritet)
                                    {
                                        UseMatch = false;
                                    }
                                }
                                if (UseMatch)
                                {
                                    rec             = r;
                                    CurVariantMatch = VariantMatch;
                                }
                            }
                        }
                    }
                }
            }

            CurVariantMatch     = 0;
            searchrec._Item     = null;
            searchrec._Variant1 = null;
            searchrec._Variant2 = null;

            if (rec == null && itemRec._DiscountGroup != null)
            {
                var discountgroup = itemRec._DiscountGroup;
                searchrec._DiscountGroup = discountgroup;
                pos = search(searchrec);
                while (pos < len)
                {
                    var r = CustomerPrices[pos++];
                    int c = string.Compare(r._DiscountGroup, discountgroup);
                    if (c != 0)
                    {
                        break;
                    }
                    if ((r._ValidFrom != DateTime.MinValue && now < r._ValidFrom) ||
                        (r._ValidTo != DateTime.MinValue && now > r._ValidTo))
                    {
                        continue;
                    }
                    if (r._Qty != 0d)
                    {
                        HasQtyPrices = true;
                    }
                    if (r._Qty <= qty)
                    {
                        rec = r;
                    }
                }
            }

            if (rec == null && itemRec._Group != null)
            {
                var group = itemRec._Group;
                searchrec._ItemGroup     = group;
                searchrec._DiscountGroup = null;
                pos = search(searchrec);
                while (pos < len)
                {
                    var r = CustomerPrices[pos++];
                    int c = string.Compare(r._ItemGroup, group);
                    if (c != 0)
                    {
                        break;
                    }
                    if ((r._ValidFrom != DateTime.MinValue && now < r._ValidFrom) ||
                        (r._ValidTo != DateTime.MinValue && now > r._ValidTo))
                    {
                        continue;
                    }
                    if (r._Qty != 0d)
                    {
                        HasQtyPrices = true;
                    }
                    if (r._Qty <= qty)
                    {
                        rec = r;
                    }
                }
            }

            if (rec != null && (IsNewItem || HasQtyPrices || CurVariantMatch >= 0))
            {
                if (rec._Pct != 0d)
                {
                    orderLine.DiscountPct = rec._Pct;
                }
                if (rec._Discount != 0d && orderLine._SalesPrice >= rec._Discount)
                {
                    orderLine.SalesPrice = orderLine._SalesPrice - rec._Discount;
                }

                if (rec._Price != 0d)
                {
                    var price = rec._Price;
                    if (OrderCurrency != PriceListCurrency)
                    {
                        if (PriceListCurrency == CompCurrency)
                        {
                            price = (ExchangeRate == 0d) ? price : Math.Round(price * ExchangeRate, 2);
                        }
                        else
                        {
                            await LookRate(orderLine, price, PriceListCurrency, OrderCurrency);

                            return;
                        }
                    }
                    orderLine.SalesPrice = price;
                }

                if (!rec._FixedContributionRate)
                {
                    return;
                }
            }

            var task = _SetPriceFromItem(orderLine, (InvItem)items.Get(orderLine._Item), rec != null ? rec._ContributionRate : 0d, rec != null ? rec._SalesCharge : 0d);

            if (task != null)
            {
                await task;
            }
        }