Пример #1
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);
        }
Пример #2
0
        private async void AddSpeakerItem(InvItemClientUser speakerItem)
        {
            // Creating new order line
            var orderLine = new DebtorOrderLineClient
            {
                _Item  = speakerItem.Item,
                _Qty   = 1,
                _Price = speakerItem.SalesPrice1
            };

            orderLine.SetMaster(this.order);

            // Calling insert API
            if (await crudAPI.Insert(orderLine) != ErrorCodes.Succes)
            {
                MessageBox.Show("ERROR: Failed to insert order line.");
                return;
            }

            // Opens another uniconta tab
            UnicontaTabs.OpenTab(UnicontaTabs.DebtorOrders, null);
        }
Пример #3
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);
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var debtor     = this.CB_Customer.SelectedItem as DebtorClient;
            var invoiceAPI = UnicontaAPIManager.GetInvoiceAPI();

            // Creating DebtorOrder
            var debtorOrder = new DebtorOrderClient
            {
                _Currency = Currencies.DKK,
            };

            debtorOrder.SetMaster(debtor);

            // Creating DebtorOrderLine's
            var debtorOrderLines = new List <DebtorOrderLineClient>();
            var debtorOrderLine  = new DebtorOrderLineClient
            {
                _Item  = "OnSiteSupport",
                _Qty   = 2.0,
                _Price = 890,
            };

            debtorOrderLine.SetMaster(debtorOrder);
            debtorOrderLines.Add(debtorOrderLine);

            // Calling Invoice API.
            var invoiceResult = await invoiceAPI.PostInvoice(debtorOrder, debtorOrderLines, DateTime.Now, 0, false, SendEmail : true, Emails : "*****@*****.**", OnlyToThisEmail : true);

            if (invoiceResult.Err != ErrorCodes.Succes)
            {
                MessageBox.Show($"Failed to send invoice: {invoiceResult.Err.ToString()}");
                return;
            }

            MessageBox.Show($"Invoice has been send InvoiceNumber:{invoiceResult.Header._InvoiceNumber}");
        }
Пример #5
0
        public void InsertSalgsfakturaer()
        {
            int?lastFakid = null;
            DebtorOrderClient recOrder = null;

            var rec_regnskab = Program.qryAktivRegnskab();
            var qrySFak      = from sfv in Program.karFakturavarer_s
                               join sf in Program.karFakturaer_s on new { fakid = sfv.Fakid } equals new { fakid = sf.fakid }
            where sf.faknr != 0 && sf.faktype == 0
            orderby sfv.Fakid, sfv.Line
                select new
            {
                Regnskabid  = rec_regnskab.Rid,
                Sk          = "S",
                Fakid       = sfv.Fakid,
                Faknr       = sf.faknr,
                Dato        = sf.dato,
                forfdato    = sf.forfdato,
                debitornr   = sf.debitornr,
                Faklinnr    = sfv.Line,
                Varenr      = sfv.Varenr,
                Tekst       = sfv.VareTekst,
                Konto       = sfv.Bogfkonto,
                Momskode    = KarKontoplan.getMomskode(sfv.Bogfkonto),
                Antal       = sfv.Antal,
                Enhed       = sfv.Enhed,
                Pris        = sfv.Pris,
                Rabat       = sfv.Rabat,
                Moms        = sfv.Moms,
                Nettobelob  = sfv.Nettobelob,
                Bruttobelob = sfv.Bruttobelob,
            };

            int antal = qrySFak.Count();

            var api = UCInitializer.GetBaseAPI;

            //var col3 = await api.Query<DebtorOrderClient>();
            //var col4 = await api.Query<DebtorOrderLineClient>();

            foreach (var s in qrySFak)
            {
                if ((!(s.Fakid == 0)) && (lastFakid != s.Fakid))
                {
                    try
                    {
                        var crit = new List <PropValuePair>();
                        var pair = PropValuePair.GenereteWhereElements("OrderNumber", typeof(int), s.Fakid.ToString());
                        crit.Add(pair);
                        var taskDebtorOrder = api.Query <DebtorOrderClient>(null, crit);
                        taskDebtorOrder.Wait();
                        var col = taskDebtorOrder.Result;
                        if (col.Count() == 0)
                        {
                            recOrder = new DebtorOrderClient()
                            {
                                OrderNumber  = s.Fakid,
                                Account      = s.debitornr.ToString(),
                                InvoiceDate  = s.Dato,
                                DeliveryDate = s.Dato,
                            };
                            var taskInsertDebtorOrder = api.Insert(recOrder);
                            taskInsertDebtorOrder.Wait();
                            var err = taskInsertDebtorOrder.Result;
                        }
                        else
                        {
                            recOrder = col[0];
                        }
                    }
                    catch { }
                }

                DebtorOrderLineClient recOrderLine = new DebtorOrderLineClient()
                {
                    Text           = s.Tekst,
                    Qty            = (double)s.Antal,
                    Price          = (double)s.Pris,
                    PostingAccount = KarNyKontoplan.NytKontonr(s.Konto)
                };
                recOrderLine.SetMaster(recOrder);
                var taskInsertDebtorOrderLine = api.Insert(recOrderLine);
                taskInsertDebtorOrderLine.Wait();
                var err1 = taskInsertDebtorOrderLine.Result;
            }
        }
        async Task CreateOrderLinesFromInvoice(DebtorOrderClient order, DebtorInvoiceClient invoice, bool checkIfCreditNote)
        {
            var orderlines = new List <DebtorOrderLineClient>();

            order.Lines = orderlines;
            var invoiceLines = await api.Query <DebtorInvoiceLines>(invoice);

            if (invoiceLines == null || invoiceLines.Length == 0)
            {
                return;
            }

            Array.Sort(invoiceLines, new InvLineSort());

            orderlines.Capacity = invoiceLines.Length;
            int    lineNo = 0;
            double sign   = checkIfCreditNote ? -1d : 1d;

            foreach (var invoiceline in invoiceLines)
            {
                var line = new DebtorOrderLineClient();
                line.SetMaster(order);

                line._LineNumber  = ++lineNo;
                line._Item        = invoiceline._Item;
                line._DiscountPct = invoiceline._DiscountPct;
                line._Discount    = invoiceline._Discount;
                line._Qty         = invoiceline.InvoiceQty * sign;
                line._Price       = (invoiceline.CurrencyEnum != null ? invoiceline._PriceCur : invoiceline._Price);
                if (line._Price != 0)
                {
                    line._Price += invoiceline._PriceVatPart;
                }

                if (line._Qty * line._Price == 0)
                {
                    line._AmountEntered = ((invoiceline.CurrencyEnum != null ? invoiceline._AmountCur : invoiceline._Amount) + invoiceline._PriceVatPart) * sign;
                }

                line._Dim1      = invoiceline._Dim1;
                line._Dim2      = invoiceline._Dim2;
                line._Dim3      = invoiceline._Dim3;
                line._Dim4      = invoiceline._Dim4;
                line._Dim5      = invoiceline._Dim5;
                line._Employee  = invoiceline._Employee;
                line._Note      = invoiceline._Note;
                line._Text      = invoiceline._Text;
                line._Unit      = invoiceline._Unit;
                line._Variant1  = invoiceline._Variant1;
                line._Variant2  = invoiceline._Variant2;
                line._Variant3  = invoiceline._Variant3;
                line._Variant4  = invoiceline._Variant4;
                line._Variant5  = invoiceline._Variant5;
                line._Warehouse = invoiceline._Warehouse;
                line._Location  = invoiceline._Location;

                var selectedItem = (InvItem)items?.Get(invoiceline._Item);
                if (selectedItem != null)
                {
                    line._Item          = selectedItem._Item;
                    line._CostPriceLine = selectedItem._CostPrice;
                    if (selectedItem._Unit != 0)
                    {
                        line._Unit = selectedItem._Unit;
                    }
                }

                orderlines.Add(line);
            }
            dcOrderlineGrid.ItemsSource = debtorOrderLines = null;
            dcOrderlineGrid.ItemsSource = debtorOrderLines = orderlines;
            dcOrderlineGrid.Visibility  = Visibility.Visible;
        }
Пример #7
0
        private async void B_Orders_Click(object sender, RoutedEventArgs e)
        {
            // Getting CrudAPI
            var crudAPI = UnicontaAPIManager.GetCrudAPI();

            crudAPI.RunInTransaction = false;

            // Parsing CSV
            var orders = CSVUtils.ParseOrders(@"C:\src\Uniconta\Technical-Training-Cases-master\TrainingData\CompanyData\Finace-Orders.csv");

            // Creating SQLCache's
            SQLCache customerCache = crudAPI.CompanyEntity.GetCache(typeof(DebtorClient));

            if (customerCache == null)
            {
                customerCache = await crudAPI.CompanyEntity.LoadCache(typeof(DebtorClient), crudAPI);
            }

            SQLCache inventoryCache = crudAPI.CompanyEntity.GetCache(typeof(InvItemClient));

            if (inventoryCache == null)
            {
                inventoryCache = await crudAPI.CompanyEntity.LoadCache(typeof(InvItemClient), crudAPI);
            }

            // Creating Insert List
            var newDebtorOrderClients = new List <DebtorOrderClient>();

            foreach (var order in orders)
            {
                // Parsing Account Number
                var accountNumber = (int.Parse(order.AccountNumber) + 20000).ToString();

                // Finding customer in cache
                var customer = customerCache.Get(accountNumber) as DebtorClient;

                var newDebtorOrderClient = new DebtorOrderClient
                {
                    _Created = order.CreatedDate
                };
                newDebtorOrderClient.SetMaster(customer);
                newDebtorOrderClients.Add(newDebtorOrderClient);
            }
            ;

            // Calling insert API
            var errorCode = await crudAPI.Insert(newDebtorOrderClients);

            if (errorCode != ErrorCodes.Succes)
            {
                MessageBox.Show($"ERROR: Failed to import orders {errorCode.ToString()}");
            }

            // Creating order lines
            var newDebtorOrderLineClients = new List <DebtorOrderLineClient>();
            var inventoryList             = inventoryCache.GetRecords as InvItemClient[];

            var index = 0;

            foreach (var debtorOrder in newDebtorOrderClients)
            {
                var orderItems = orders[index].Items;
                foreach (var item in orderItems)
                {
                    var inventoryItem = inventoryList.FirstOrDefault(i => i.Name == item.ItemName);

                    var orderLine = new DebtorOrderLineClient
                    {
                        _Item  = inventoryItem.Item,
                        _Qty   = 1,
                        _Price = inventoryItem.SalesPrice1
                    };
                    orderLine.SetMaster(debtorOrder);
                    newDebtorOrderLineClients.Add(orderLine);
                }
                ;

                index++;
            }
            ;

            // Calling insert API
            var errorCode2 = await crudAPI.Insert(newDebtorOrderLineClients);

            if (errorCode2 != ErrorCodes.Succes)
            {
                MessageBox.Show($"ERROR: Failed to import order lines {errorCode2.ToString()}");
            }
            else
            {
                MessageBox.Show("Import Completed");
            }
        }
        ////summary
        //// The Execute method to execute on the basis of parameter passed
        ////summary
        ////Params UnicontaBaseEntity master :- To pass the master table
        ////Params UnicontaBaseEntity currentRow :- To pass the current row
        ////Params IEnumerable<UnicontaBaseEntity> source :- To pass List of UnicontaBaseEntity
        ////Params String Command :- pass the command
        ////Params String args :- pass the argument
        ////Returns ErrorCodes
        public ErrorCodes Execute(UnicontaBaseEntity master, UnicontaBaseEntity currentRow, IEnumerable <UnicontaBaseEntity> source, string command, string args)
        {
            if (currentRow == null || !(currentRow is DebtorOrderClient))
            {
                MessageBox.Show("ERROR: No row or wrong type");
                return(ErrorCodes.Exception);
            }

            // Parse currentRow
            var order = currentRow as DebtorOrderClient;

            // Parse args
            var itemList = args.Split(',').Select(x => x.Split(':')).ToList();

            if (itemList == null)
            {
                MessageBox.Show("No Args");
                return(ErrorCodes.Exception);
            }

            // Getting Items
            var itemFilter = "";

            itemList.ForEach(item => itemFilter += $"{item[0]};");

            var itemFilters = new List <PropValuePair> {
                PropValuePair.GenereteWhereElements("KeyName", typeof(string), itemFilter)
            };
            var items = crudAPI.Query <InvItemClient>(itemFilters).Result.ToList();

            // Creating new order lines
            var newOrderLines = new List <DebtorOrderLineClient>();

            foreach (var item in items)
            {
                var itemQty = itemList.FirstOrDefault(x => x[0] == item.KeyName);
                if (itemQty == null)
                {
                    continue;
                }

                var orderLine = new DebtorOrderLineClient
                {
                    _Item  = item.Item,
                    _Qty   = double.Parse(itemQty[1]),
                    _Price = item.SalesPrice1
                };
                orderLine.SetMaster(order);

                newOrderLines.Add(orderLine);
            }

            // Call insert API
            var insertError = crudAPI.Insert(newOrderLines).Result;

            if (insertError != ErrorCodes.Succes)
            {
                MessageBox.Show("ERROR: Failed to insert order lines");
                return(ErrorCodes.Exception);
            }

            // Attacting UserDocument to order.
            var            imageFile  = File.ReadAllBytes(@"C:\src\Uniconta\Technical-Training-Cases-master\TrainingData\LIGHT-FLOORPANEL.jpg");
            UserDocsClient newUserDoc = new UserDocsClient
            {
                Created      = DateTime.Now,
                DocumentType = FileextensionsTypes.JPEG,
                Text         = "LIGHT-FLOORPANEL.jpg",
                _Data        = imageFile,
            };

            newUserDoc.SetMaster(order);

            // Calling insert API
            if (crudAPI.Insert(newUserDoc).Result != ErrorCodes.Succes)
            {
                MessageBox.Show("ERROR: Failed to insert UserDocument");
                return(ErrorCodes.Exception);
            }

            // Writes file to disk
            var orderDocuments = crudAPI.Query <UserDocsClient>(order).Result;

            if (orderDocuments.Length != 0)
            {
                var readResult = crudAPI.Read(orderDocuments[0]).Result;
                var fileBytes  = orderDocuments[0]._Data;

                if (orderDocuments[0].DocumentType == FileextensionsTypes.JPEG)
                {
                    File.WriteAllBytes(@"C:\src\Uniconta\Technical-Training-Cases-master\TrainingData\LIGHT-FLOORPANEL-return.jpg", fileBytes);
                }
            }

            // Refresh Grid View
            if (OnExecute != null)
            {
                PluginEventArgs arg = new PluginEventArgs();
                arg.EventType = PluginEvent.RefreshGrid;
                OnExecute(null, arg);
            }

            return(ErrorCodes.Succes);
        }