示例#1
0
        protected override async void LoadCacheInBackGround()
        {
            var api  = this.api;
            var Comp = api.CompanyEntity;

            if (this.items == null)
            {
                this.items = api.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvItem)).ConfigureAwait(false);
            }
            if (Comp.ItemVariants)
            {
                if (this.standardVariants == null)
                {
                    this.standardVariants = api.GetCache(typeof(Uniconta.DataModel.InvStandardVariant)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvStandardVariant)).ConfigureAwait(false);
                }
                if (this.variants1 == null)
                {
                    this.variants1 = api.GetCache(typeof(Uniconta.DataModel.InvVariant1)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvVariant1)).ConfigureAwait(false);
                }
                if (this.variants2 == null)
                {
                    this.variants2 = api.GetCache(typeof(Uniconta.DataModel.InvVariant2)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvVariant2)).ConfigureAwait(false);
                }
            }

            if (this.PriceLookup == null && Order != null)
            {
                PriceLookup = new Uniconta.API.DebtorCreditor.FindPrices(Order, api);
            }
            var t = this.PriceLookup?.ExchangeTask;

            this.exchangeRate = this.PriceLookup != null ? this.PriceLookup.ExchangeRate : 0d;
            if (this.exchangeRate == 0d && t != null)
            {
                this.exchangeRate = await t.ConfigureAwait(false);
            }

            this.employees = api.GetCache(typeof(Uniconta.DataModel.Employee)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Employee)).ConfigureAwait(false);

            Dispatcher.BeginInvoke(new Action(() =>
            {
                var selectedItem = dgProjInvProposedLineGrid.SelectedItem as ProjectInvoiceProposalLineClient;
                if (selectedItem != null)
                {
                    if (selectedItem.Variant1Source == null)
                    {
                        setVariant(selectedItem, false);
                    }
                    if (selectedItem.Variant2Source == null)
                    {
                        setVariant(selectedItem, true);
                    }
                }
            }));
            if (Comp.DeliveryAddress)
            {
                LoadType(typeof(Uniconta.DataModel.WorkInstallation));
            }
        }
示例#2
0
        void SetupMaster(UnicontaBaseEntity args)
        {
            PriceLookup = null;
            var OrderId = Order?.RowId;

            dgProjInvProposedLineGrid.UpdateMaster(args);
            if (Order?.RowId != OrderId)
            {
                PriceLookup = new Uniconta.API.DebtorCreditor.FindPrices(Order, api);
            }
        }
示例#3
0
        private ErrorCodes CreateLines(List <string[]> lines, DebtorClient debtorClient)
        {
            var ols   = new List <DebtorOrderLineClient>();
            var items = _crudAPI.Query <InvItemClient>().Result;

            var order = new DebtorOrderClient();

            order.SetMaster(debtorClient);
            var orderres = _crudAPI.Insert(order).Result;

            foreach (string[] s in lines)
            {
                var item = items.First(i => i.Item == s[1]);

                var fp = new FindPrices(order, _crudAPI);
                fp.UseCustomerPrices = true;
                fp.loadPriceList();

                var ol = new DebtorOrderLineClient
                {
                    Qty  = double.Parse(s[2]),
                    Item = item.Item,
                    //Date = DateTime.Parse(s[3]),
                };
                ol.SetMaster(order);

                fp.SetPriceFromItem(ol, item);

                ols.Add(ol);
            }

            var result = _crudAPI.Insert(ols).Result;

            if (result == ErrorCodes.Succes)
            {
                openOrderLines(order);
            }

            return(result);
        }
示例#4
0
        private async void createLines(List <string[]> lines)
        {
            var orders = new List <DebtorOrderClient>();
            var ols    = new List <DebtorOrderLineClient>();
            var items  = await crudAPI.Query <InvItemClient>();

            var debtors = await crudAPI.Query <DebtorClient>();

            foreach (string[] s in lines)
            {
                DebtorOrderClient order;
                order = orders.Where(o => o.Account == s[0]).FirstOrDefault();
                if (order == null)
                {
                    order = new DebtorOrderClient();
                    order.SetMaster(debtors.Where(d => d.Account == s[0]).First());
                    orders.Add(order);
                    var orderres = await crudAPI.Insert(order);
                }

                var item = items.Where(i => i.Item == s[1]).First();

                var fp = new FindPrices(order, crudAPI);
                fp.UseCustomerPrices = true;
                fp.loadPriceList();

                var ol = new DebtorOrderLineClient
                {
                    Qty  = double.Parse(s[2]),
                    Item = item.Item,
                    Date = DateTime.Parse(s[3]),
                };
                ol.SetMaster(order);

                fp.SetPriceFromItem(ol, item);

                await crudAPI.Insert(ol);
            }
        }
示例#5
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;
            }
        }