public void InsertKøbsOrder(MimeMessage message, int DocumentRef, clsParam objParam) { var From = message.From.ToString(); From = ExtractEmails(From); var Date = message.Date.DateTime; var Subject = objParam.Tekst; if (string.IsNullOrEmpty(Subject)) { Subject = message.Subject; } string wAccount = null; try { wAccount = (from c in this.m_Creditors where c.Account == objParam.Konto select c.Account).First(); } catch (Exception) { try { wAccount = (from c in this.m_Creditors where ((c.ContactEmail != null) && (c.ContactEmail.ToLower() == From.ToLower())) || ((c._InvoiceEmail != null) && (c._InvoiceEmail.ToLower() == From.ToLower())) select c.Account).First(); } catch { wAccount = "100000"; //Ukendt kreditor } } CreditorOrderClient recOrder = new CreditorOrderClient() { Account = wAccount, InvoiceDate = Date, DeliveryDate = Date, DocumentRef = DocumentRef, DeleteLines = true, DeleteOrder = true }; var taskInsertCreditorOrder = m_api.Insert(recOrder); taskInsertCreditorOrder.Wait(); var err1 = taskInsertCreditorOrder.Result; CreditorOrderLineClient recOrderLine = new CreditorOrderLineClient() { Text = Subject, Qty = 1, Price = objParam.Kredit == null ? 0 : (double)objParam.Kredit, PostingAccount = objParam.Modkonto, }; recOrderLine.SetMaster(recOrder); var taskInsertCreditorOrderLine = m_api.Insert(recOrderLine); taskInsertCreditorOrderLine.Wait(); var err2 = taskInsertCreditorOrderLine.Result; }
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; } }