Example #1
0
        public void InsertKøbsfakturaer()
        {
            int?lastFakid = null;
            CreditorOrderClient recOrder = null;

            var rec_regnskab = Program.qryAktivRegnskab();
            var qryKFak      = from kfv in Program.karFakturavarer_k
                               join kf in Program.karFakturaer_k on new { fakid = kfv.Fakid } equals new { fakid = kf.fakid }
            where kf.faknr != 0 && kf.faktype == 2
            orderby kfv.Fakid, kfv.Line
                select new
            {
                Regnskabid  = rec_regnskab.Rid,
                Sk          = "K",
                Fakid       = kfv.Fakid,
                Faknr       = kf.faknr,
                Dato        = kf.dato,
                kreditornr  = kf.kreditornr,
                Faklinnr    = kfv.Line,
                Varenr      = kfv.Varenr,
                Tekst       = kfv.VareTekst,
                Konto       = kfv.Bogfkonto,
                Momskode    = KarKontoplan.getMomskode(kfv.Bogfkonto),
                Antal       = kfv.Antal,
                Enhed       = kfv.Enhed,
                Pris        = kfv.Pris,
                Rabat       = kfv.Rabat,
                Moms        = kfv.Moms,
                Nettobelob  = kfv.Nettobelob,
                Bruttobelob = kfv.Bruttobelob,
            };

            int antal = qryKFak.Count();

            var api = UCInitializer.GetBaseAPI;

            //var col3 = await api.Query<CreditorOrderClient>();
            //var col4 = await api.Query<CreditorOrderLineClient>();

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

                CreditorOrderLineClient recOrderLine = new CreditorOrderLineClient()
                {
                    Text           = k.Tekst,
                    Qty            = (double)k.Antal,
                    Price          = (double)k.Pris,
                    PostingAccount = KarNyKontoplan.NytKontonr(k.Konto)
                };
                recOrderLine.SetMaster(recOrder);
                var taskInsertCreditorOrderLine = api.Insert(recOrderLine);
                taskInsertCreditorOrderLine.Wait();
                var err1 = taskInsertCreditorOrderLine.Result;
            }
        }
Example #2
0
        async public void InsertGLDailyJournalLinesYearEnd()
        {
            var api  = UCInitializer.GetBaseAPI;
            var col3 = await api.Query <NumberSerieClient>();

            var crit = new List <PropValuePair>();
            var pair = PropValuePair.GenereteWhereElements("KeyStr", typeof(String), "Dag");

            crit.Add(pair);
            var col = await api.Query <GLDailyJournalClient>(null, crit);

            var rec_Master = col.FirstOrDefault();


            var qryPosteringer = from p in Program.karPosteringer
                                 where p.Bilag == 0 && (p.Tekst.StartsWith("ÅP:") || p.Tekst.StartsWith("EP:"))
                                 orderby p.Konto, p.Nr
            select p;

            int antal = qryPosteringer.Count();

            DateTime Dato_last      = DateTime.Today;
            int      Konto_last     = 0;
            decimal  Nettobeløb_sum = 0;

            foreach (var p in qryPosteringer)
            {
                if (p.Konto != Konto_last)
                {
                    if (Konto_last != 0)
                    {
                        GLDailyJournalLineClient jl = new GLDailyJournalLineClient()
                        {
                            Date    = Dato_last,
                            Voucher = 9999,
                            Text    = "Primo SummaSummarum",
                            Account = KarNyKontoplan.NytKontonr(Konto_last)
                        };

                        if (Nettobeløb_sum > 0)
                        {
                            jl.Debit = (double)Nettobeløb_sum;
                        }
                        else
                        {
                            jl.Credit = -(double)Nettobeløb_sum;
                        }

                        jl.SetMaster(rec_Master);
                        var err = await api.Insert(jl);
                    }
                    Nettobeløb_sum = 0;
                }
                Dato_last       = p.Dato;
                Konto_last      = p.Konto;
                Nettobeløb_sum += p.Nettobeløb;
            }

            if (antal > 0)
            {
                GLDailyJournalLineClient jl = new GLDailyJournalLineClient()
                {
                    Date    = Dato_last,
                    Voucher = 9999,
                    Text    = "Primo SummaSummarum",
                    Account = KarNyKontoplan.NytKontonr(Konto_last)
                };

                if (Nettobeløb_sum > 0)
                {
                    jl.Debit = (double)Nettobeløb_sum;
                }
                else
                {
                    jl.Credit = -(double)Nettobeløb_sum;
                }

                jl.SetMaster(rec_Master);
                var err = await api.Insert(jl);
            }
        }
Example #3
0
        async public void InsertGLDailyJournalLines()
        {
            var api = UCInitializer.GetBaseAPI;
            //var col3 = await api.Query<NumberSerieClient>();

            var crit = new List <PropValuePair>();
            var pair = PropValuePair.GenereteWhereElements("KeyStr", typeof(String), "Dag");

            crit.Add(pair);
            var col = await api.Query <GLDailyJournalClient>(null, crit);

            var rec_Master = col.FirstOrDefault();

            var qryKladder = from k in Program.karKladder
                             where k.Bilag > 183 // <-----------------------
                             orderby k.Bilag, k.Id
            select k;
            int antal = qryKladder.Count();

            foreach (var k in qryKladder)
            {
                //if (k.Bilag > 3)
                //    break;
                int refbilag = await InsertVouchersClients(k);

                GLDailyJournalLineClient jl = new GLDailyJournalLineClient()
                {
                    Date        = (DateTime)k.Dato,
                    Voucher     = (k.Bilag != null) ? (int)k.Bilag : 0,
                    Text        = k.Tekst,
                    DocumentRef = refbilag,
                };


                if (!String.IsNullOrWhiteSpace(k.Afstemningskonto)) //Afstemningskonto er udfyldt
                {
                    if (k.Belob > 0)
                    {
                        jl.Debit = (double)k.Belob;
                    }
                    else
                    {
                        jl.Credit = -(double)k.Belob;
                    }
                }
                else //Afstemningskonto er ikke udfyldt
                {
                    if (k.Belob > 0)
                    {
                        jl.Credit = (double)k.Belob;
                    }
                    else
                    {
                        jl.Debit = -(double)k.Belob;
                    }
                }

                if (KarNyKontoplan.NytKontonr(k.Afstemningskonto) != string.Empty)
                {
                    jl.Account = KarNyKontoplan.NytKontonr(k.Afstemningskonto);

                    if (KarNyKontoplan.NytKontonr(k.Konto) != string.Empty)
                    {
                        jl.OffsetAccount = KarNyKontoplan.NytKontonr(k.Konto);
                    }
                }
                else
                {
                    if (KarNyKontoplan.NytKontonr(k.Konto) != string.Empty)
                    {
                        jl.Account = KarNyKontoplan.NytKontonr(k.Konto);
                    }
                }
                jl.Dimension1 = KarDimensionSag.getDimension1(k.Sag);
                jl.Dimension2 = KarDimensionSag.getDimension2(k.Sag);
                jl.SetMaster(rec_Master);
                var err = await api.Insert(jl);
            }
        }