Esempio n. 1
0
        void RecalculateAmount()
        {
            var        ret              = DebtorOfferLines.RecalculateLineSum((IList)dgCreditorOrderLineGrid.ItemsSource, this.exchangeRate);
            double     Amountsum        = ret.Item1;
            double     Costsum          = ret.Item2;
            double     AmountsumCompCur = ret.Item3;
            RibbonBase rb     = (RibbonBase)localMenu.DataContext;
            var        groups = UtilDisplay.GetMenuCommandsByStatus(rb, true);

            foreach (var grp in groups)
            {
                grp.StatusValue = Amountsum.ToString("N2");
            }
        }
Esempio n. 2
0
        void RecalculateAmount()
        {
            var ord = this.Order;

            if (ord == null)
            {
                return;
            }
            var    ret       = DebtorOfferLines.RecalculateLineSum(ord, (IEnumerable <DCOrderLineClient>)dgProjInvProposedLineGrid.ItemsSource, this.exchangeRate);
            double Amountsum = ret.Item1;
            double Costsum   = ret.Item2;
            double sales     = ret.Item3;

            ord._OrderTotal = sales;
            if (ord._EndDiscountPct != 0)
            {
                sales *= (100d - ord._EndDiscountPct) / 100d;
            }

            RibbonBase rb     = (RibbonBase)localMenu.DataContext;
            var        groups = UtilDisplay.GetMenuCommandsByStatus(rb, true);

            var strAmount    = Uniconta.ClientTools.Localization.lookup("Amount");
            var strCost      = Uniconta.ClientTools.Localization.lookup("CostValue");
            var strDB        = Uniconta.ClientTools.Localization.lookup("DB");
            var strProjTotal = Uniconta.ClientTools.Localization.lookup("ProjectTotal");

            foreach (var grp in groups)
            {
                if (grp.Caption == strAmount)
                {
                    grp.StatusValue = Amountsum.ToString("N2");
                }
                else if (grp.Caption == strCost)
                {
                    grp.StatusValue = Costsum.ToString("N2");
                }
                else if (grp.Caption == strDB)
                {
                    var    margin = (sales - Costsum);
                    var    ratio  = sales != 0d ? Math.Round(margin * 100d / sales) : 0d;
                    string str;
                    if (ratio != 0 && ratio != 100 && ratio > -100)
                    {
                        str = string.Format("{0}% {1:n2}", ratio, margin);
                    }
                    else
                    {
                        str = margin.ToString("N2");
                    }
                    grp.StatusValue = str;
                }
                else if (grp.Caption == strProjTotal)
                {
                    grp.StatusValue = ord._ProjectTotal.ToString("N2");
                }
                else
                {
                    grp.StatusValue = string.Empty;
                }
            }
        }
Esempio n. 3
0
        private void SelectedItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var rec = sender as CreditorOrderLineClient;

            switch (e.PropertyName)
            {
            case "Item":
                var selectedItem = (InvItem)items?.Get(rec._Item);
                if (selectedItem != null)
                {
                    if (selectedItem._AlternativeItem != null &&
                        selectedItem._UseAlternative == UseAlternativeItem.Always)
                    {
                        var altItem = (InvItem)items.Get(selectedItem._AlternativeItem);
                        if (altItem != null && altItem._AlternativeItem == null)
                        {
                            rec.Item = selectedItem._AlternativeItem;
                            return;
                        }
                    }
                    var _priceLookup = this.PriceLookup;
                    this.PriceLookup = null;     // avoid that we call priceupdated in property change on Qty
                    var Comp = api.CompanyEntity;
                    if (selectedItem._PurchaseQty != 0d)
                    {
                        rec.Qty = selectedItem._PurchaseQty;
                    }
                    else if (Comp._PurchaseLineOne)
                    {
                        rec.Qty = 1d;
                    }
                    rec.SetItemValues(selectedItem, Comp._PurchaseLineStorage);
                    if (_priceLookup != null)
                    {
                        this.PriceLookup = _priceLookup;
                        _priceLookup.SetPriceFromItem(rec, selectedItem);
                    }
                    else if (selectedItem._PurchasePrice != 0 && Comp.SameCurrency(selectedItem._PurchaseCurrency, (byte)this.Order._Currency))
                    {
                        rec.Price = selectedItem._PurchasePrice;
                    }
                    else
                    {
                        rec.Price = (exchangeRate == 0d) ? selectedItem._CostPrice : Math.Round(selectedItem._CostPrice * exchangeRate, 2);
                    }
                    if (selectedItem._StandardVariant != rec.standardVariant)
                    {
                        rec.Variant1       = null;
                        rec.Variant2       = null;
                        rec.variant2Source = null;
                        rec.NotifyPropertyChanged("Variant2Source");
                    }
                    setVariant(rec, false);
                    TableField.SetUserFieldsFromRecord(selectedItem, rec);
                    if (selectedItem._Blocked)
                    {
                        UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null);
                    }
                }
                break;

            case "Qty":
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                break;

            case "Warehouse":
                if (warehouse != null)
                {
                    var selected = (InvWarehouse)warehouse.Get(rec._Warehouse);
                    setLocation(selected, (CreditorOrderLineClient)rec);
                }
                break;

            case "Location":
                if (string.IsNullOrEmpty(rec._Warehouse))
                {
                    rec._Location = null;
                }
                break;

            case "EAN":
                DebtorOfferLines.FindOnEAN(rec, this.items, api, this.PriceLookup);
                break;

            case "Total":
                RecalculateAmount();
                break;

            case "Variant1":
                if (rec._Variant1 != null)
                {
                    setVariant(rec, true);
                }
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                break;

            case "Variant2":
            case "Variant3":
            case "Variant4":
            case "Variant5":
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                break;

            case "Project":
                if (ProjectCache != null)
                {
                    var selected = (ProjectClient)ProjectCache.Get(rec._Project);
                    setTask(selected, rec);
                }
                break;

            case "Task":
                if (string.IsNullOrEmpty(rec._Project))
                {
                    rec._Task = null;
                }
                break;
            }
        }
Esempio n. 4
0
        private void ProjInvProposedLineGrid_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var rec = sender as ProjectInvoiceProposalLineClient;

            switch (e.PropertyName)
            {
            case "Item":
                var selectedItem = (InvItem)items?.Get(rec._Item);
                if (selectedItem != null)
                {
                    if (selectedItem._AlternativeItem != null && selectedItem._UseAlternative == UseAlternativeItem.Always)
                    {
                        var altItem = (InvItem)items.Get(selectedItem._AlternativeItem);
                        if (altItem != null && altItem._AlternativeItem == null)
                        {
                            rec.Item = selectedItem._AlternativeItem;
                            return;
                        }
                    }

                    var _priceLookup = this.PriceLookup;
                    this.PriceLookup = null;     // avoid that we call priceupdated in property change on Qty
                    if (selectedItem._SalesQty != 0d)
                    {
                        rec.Qty = selectedItem._SalesQty;
                    }
                    else if (api.CompanyEntity._OrderLineOne)
                    {
                        rec.Qty = 1d;
                    }
                    rec.SetItemValues(selectedItem, api.CompanyEntity._OrderLineStorage);
                    this.PriceLookup = _priceLookup;
                    _priceLookup?.SetPriceFromItem(rec, selectedItem);

                    if (company._InvoiceUseQtyNow)
                    {
                        rec.QtyNow = rec._Qty;
                    }

                    if (selectedItem._StandardVariant != rec.standardVariant)
                    {
                        rec.Variant1       = null;
                        rec.Variant2       = null;
                        rec.variant2Source = null;
                        rec.NotifyPropertyChanged("Variant2Source");
                    }
                    setVariant(rec, false);
                    TableField.SetUserFieldsFromRecord(selectedItem, rec);
                    if (selectedItem._Blocked)
                    {
                        UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null);
                    }

                    globalEvents.NotifyRefreshViewer(NameOfControl, rec);
                }
                break;

            case "Qty":
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                if (company._InvoiceUseQtyNow)
                {
                    rec.QtyNow = rec._Qty;
                }
                break;

            case "Subtotal":
            case "Total":
                Dispatcher.BeginInvoke(new Action(() => { RecalculateAmount(); }));
                break;

            case "Employee":
                if (rec._Employee != null)
                {
                    var item = (InvItem)items?.Get(rec._Item);
                    if (item == null || item._ItemType == (byte)Uniconta.DataModel.ItemType.Service)
                    {
                        var emp = (Uniconta.DataModel.Employee)employees?.Get(rec._Employee);
                        if (emp != null && emp._CostPrice != 0d)
                        {
                            rec.CostPrice = emp._CostPrice;
                        }
                    }
                }
                break;

            case "EAN":
                DebtorOfferLines.FindOnEAN(rec, this.items, api, this.PriceLookup);
                break;

            case "Variant1":
                if (rec._Variant1 != null)
                {
                    setVariant(rec, true);
                }
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                break;

            case "Variant2":
            case "Variant3":
            case "Variant4":
            case "Variant5":
                if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices)
                {
                    this.PriceLookup.GetCustomerPrice(rec, false);
                }
                break;

            case "Variant":
                globalEvents.NotifyRefreshViewer(NameOfControl, rec);
                break;

            case "CustomerItemNumber":
                if (!string.IsNullOrEmpty(rec.CustomerItemNumber))
                {
                    DebtorOfferLines.FindItemFromCustomerItem(rec, Order, api, rec.CustomerItemNumber);
                }
                break;
            }
        }