public void TestFakturering() { InvoiceAPI invoiceAPI = new InvoiceAPI(m_api); var taskDebtorOrder = m_api.Query <DebtorOrderClient>(); taskDebtorOrder.Wait(); var DebtorOrders = taskDebtorOrder.Result; foreach (var DebtorOrder in DebtorOrders) { List <DebtorOrderClient> Masters = new List <DebtorOrderClient>(); Masters.Add(DebtorOrder); var taskDebtorOrderLines = m_api.Query <DebtorOrderLineClient>(Masters, null); taskDebtorOrderLines.Wait(); var DebtorOrderLines = taskDebtorOrderLines.Result; var taskInvoice = invoiceAPI.PostInvoice(DebtorOrder, DebtorOrderLines, DateTime.Now, 0, true, null, null); taskInvoice.Wait(); InvoicePostingResult resultInvoice = taskInvoice.Result; ErrorCodes Err = resultInvoice.Err; DCInvoice Header = resultInvoice.Header; IEnumerable <InvTrans> Lines = resultInvoice.Lines; PostingResult ledgerRes = resultInvoice.ledgerRes; if (Err == ErrorCodes.Succes) { var xxx = DebtorOrder.InvoiceInterval; var yyy = DebtorOrder.Invoices; } } }
static public void SetGLNnumber(DCInvoice InvClient, DCAccount client, QueryAPI api) { var installation = (WorkInstallation)api.GetCache(typeof(WorkInstallation))?.Get(InvClient._Installation); var dctype = InvClient.__DCType(); var dccache = api.GetCache((dctype == 2 || dctype == 9) ? typeof(Uniconta.DataModel.Creditor) : typeof(Uniconta.DataModel.Debtor)); var debtor = client ?? (DCAccount)dccache?.Get(InvClient._DCAccount); var contact = (Contact)api.GetCache(typeof(Contact))?.Get(InvClient._ContactRef); InvClient._EAN = installation?._GLN ?? contact?._EAN ?? debtor?._EAN; }
static public void SetGLNnumber(DCInvoice InvClient, DCAccount client, QueryAPI api) { var Comp = api.CompanyEntity; var installation = (WorkInstallation)Comp.GetCache(typeof(WorkInstallation), api)?.Get(InvClient._Installation); var deliveryAccount = (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DeliveryAccount); var debtor = client ?? (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DCAccount); var contact = (Contact)Comp.GetCache(typeof(Contact), api)?.Get(InvClient._ContactRef); InvClient._EAN = installation?._GLN ?? deliveryAccount?._EAN ?? contact?._EAN ?? debtor?._EAN; }
static public void SetDeliveryAdress(DCInvoice InvClient, DCAccount client, QueryAPI api) { SetGLNnumber(InvClient, client, api); if (InvClient._DeliveryAddress1 != null) { return; } if (InvClient._Installation != null) { var wInsCache = api.GetCache(typeof(WorkInstallation)) ?? api.LoadCache(typeof(WorkInstallation)).GetAwaiter().GetResult(); var installation = (WorkInstallation)wInsCache.Get(InvClient._Installation); if (installation == null) { wInsCache = api.LoadCache(typeof(WorkInstallation), true).GetAwaiter().GetResult(); installation = (WorkInstallation)wInsCache.Get(InvClient._Installation); } if (installation != null) { InvClient._DeliveryName = installation._Name; InvClient._DeliveryAddress1 = installation._Address1; InvClient._DeliveryAddress2 = installation._Address2; InvClient._DeliveryAddress3 = installation._Address3; InvClient._DeliveryZipCode = installation._ZipCode; InvClient._DeliveryCity = installation._City; if (api.CompanyEntity._Country != (byte)installation._Country) { InvClient._DeliveryCountry = installation._Country; } } } else { DCAccount deb = null; string ac; bool UseDebAddress; if (InvClient._DeliveryAccount != null) { ac = InvClient._DeliveryAccount; UseDebAddress = true; } else { UseDebAddress = false; if (client != null) { deb = client; ac = null; } else { ac = InvClient._DCAccount; } } if (ac != null) { var dctype = InvClient.__DCType(); var t = (dctype == 2 || dctype == 9) ? typeof(Uniconta.DataModel.Creditor) : typeof(Uniconta.DataModel.Debtor); var dcCache = api.GetCache(t) ?? api.LoadCache(t).GetAwaiter().GetResult(); deb = (DCAccount)dcCache.Get(ac); if (deb == null) { dcCache = api.LoadCache(t, true).GetAwaiter().GetResult(); deb = (DCAccount)dcCache.Get(ac); } } if (deb != null) { if (deb._DeliveryAddress1 != null) { InvClient._DeliveryName = deb._DeliveryName; InvClient._DeliveryAddress1 = deb._DeliveryAddress1; InvClient._DeliveryAddress2 = deb._DeliveryAddress2; InvClient._DeliveryAddress3 = deb._DeliveryAddress3; InvClient._DeliveryZipCode = deb._DeliveryZipCode; InvClient._DeliveryCity = deb._DeliveryCity; InvClient._DeliveryCountry = deb._DeliveryCountry; } else if (UseDebAddress) { InvClient._DeliveryName = deb._Name; InvClient._DeliveryAddress1 = deb._Address1; InvClient._DeliveryAddress2 = deb._Address2; InvClient._DeliveryAddress3 = deb._Address3; InvClient._DeliveryZipCode = deb._ZipCode; InvClient._DeliveryCity = deb._City; if (api.CompanyEntity._Country != (byte)deb._Country) { InvClient._DeliveryCountry = deb._Country; } } } } }
public static async void GenerateOIOXml(CrudAPI api, DCInvoice inv) { var Comp = api.CompanyEntity; var InvCache = api.GetCache(typeof(Uniconta.DataModel.InvItem)) ?? await api.LoadCache(typeof(Uniconta.DataModel.InvItem)); var VatCache = api.GetCache(typeof(Uniconta.DataModel.GLVat)) ?? await api.LoadCache(typeof(Uniconta.DataModel.GLVat)); //SystemInfo.Visible = true; int countErr = 0; SaveFileDialog saveDialog = null; Uniconta.API.DebtorCreditor.InvoiceAPI Invapi = new Uniconta.API.DebtorCreditor.InvoiceAPI(api); var listPropval = new List <PropValuePair>() { PropValuePair.GenereteWhereElements("InvoiceNumber", inv._InvoiceNumber, CompareOperator.Equal), PropValuePair.GenereteWhereElements("DCAccount", inv._DCAccount, CompareOperator.Equal), PropValuePair.GenereteWhereElements("Date", inv._Date, CompareOperator.Equal) }; var FindDebInvLocal = await api.Query <DebtorInvoiceClient>(listPropval); var invClient = FindDebInvLocal.FirstOrDefault(); if (invClient == null) { return; } var Debcache = Comp.GetCache(typeof(Debtor)) ?? await api.LoadCache(typeof(Debtor)); var debtor = (Debtor)Debcache.Get(invClient._DCAccount); if (debtor == null || !debtor._InvoiceInXML || invClient.SendTimeOIO != DateTime.MinValue) { if (!debtor._InvoiceInXML) { UnicontaMessageBox.Show("Faktura i OIOUBL er ikke sat til denne debitor", Uniconta.ClientTools.Localization.lookup("Warning")); } return; } var InvTransInvoiceLines = (DebtorInvoiceLines[])await Invapi.GetInvoiceLines(invClient, new DebtorInvoiceLines()); //TODO:Test fakturering var layoutGroupCache = api.GetCache(typeof(DebtorLayoutGroup)) ?? await api.LoadCache(typeof(DebtorLayoutGroup)); Contact contactPerson = null; if (invClient._ContactRef != 0) { var Contacts = api.GetCache(typeof(Uniconta.DataModel.Contact)) ?? await api.LoadCache(typeof(Uniconta.DataModel.Contact)); foreach (var contact in (Uniconta.DataModel.Contact[])Contacts.GetRecords) { if (contact.RowId == invClient._ContactRef) { contactPerson = contact; break; } } } DebtorOrders.SetDeliveryAdress(invClient, debtor, api); Debtor deliveryAccount; if (invClient._DeliveryAccount != null) { deliveryAccount = (Debtor)Debcache.Get(invClient._DeliveryAccount); } else { deliveryAccount = null; } WorkInstallation workInstallation = null; if (invClient._Installation != null) { var workInstallCache = api.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) ?? await api.LoadCache(typeof(Uniconta.DataModel.WorkInstallation)); workInstallation = (WorkInstallation)workInstallCache.Get(invClient._Installation); } CreationResult result; if (Comp._CountryId == CountryCode.Norway || Comp._CountryId == CountryCode.Netherlands) { result = EHF.GenerateEHFXML(Comp, debtor, deliveryAccount, invClient, InvTransInvoiceLines, InvCache, VatCache, null, contactPerson); } else { var attachments = await FromXSDFile.OIOUBL.ExportImport.Attachments.CollectInvoiceAttachments(invClient, api); result = Uniconta.API.DebtorCreditor.OIOUBL.GenerateOioXML(Comp, debtor, deliveryAccount, invClient, InvTransInvoiceLines, InvCache, VatCache, null, contactPerson, attachments, layoutGroupCache, workInstallation); } bool createXmlFile = true; var errorInfo = ""; if (result.HasErrors) { countErr++; createXmlFile = false; foreach (FromXSDFile.OIOUBL.ExportImport.PrecheckError error in result.PrecheckErrors) { errorInfo += error.ToString() + "\n"; } } if (result.Document != null && createXmlFile) { string invoice = Uniconta.ClientTools.Localization.lookup("Invoice"); saveDialog = Uniconta.ClientTools.Util.UtilDisplay.LoadSaveFileDialog; saveDialog.FileName = string.Format("{0}_{1}", invoice, invClient.InvoiceNumber); saveDialog.Filter = "XML-File | *.xml"; bool?dialogResult = saveDialog.ShowDialog(); if (dialogResult != true) { return; } var filename = saveDialog.FileName; result.Document.Save(filename); await Invapi.MarkSendInvoiceOIO(invClient); invClient.SendTimeOIO = BasePage.GetSystemDefaultDate(); } //invClient.NotifySystemInfoSet(); //if (countErr != 0) // UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup(String.Format("Couldn't create file for {0} invoice(s). Please check System info column.", countErr))); if (countErr != 0 && !string.IsNullOrWhiteSpace(errorInfo)) { UnicontaMessageBox.Show(errorInfo, Uniconta.ClientTools.Localization.lookup("Error")); } }
static public void SetDeliveryAdress(DCInvoice InvClient, DCAccount client, QueryAPI api) { SetGLNnumber(InvClient, client, api); if (InvClient._DeliveryAddress1 != null) { return; } var Comp = api.CompanyEntity; if (InvClient._Installation != null) { var installation = (WorkInstallation)Comp.GetCache(typeof(WorkInstallation), api)?.Get(InvClient._Installation); if (installation != null) { InvClient._DeliveryName = installation._Name; InvClient._DeliveryAddress1 = installation._Address1; InvClient._DeliveryAddress2 = installation._Address2; InvClient._DeliveryAddress3 = installation._Address3; InvClient._DeliveryZipCode = installation._ZipCode; InvClient._DeliveryCity = installation._City; if (Comp._Country != (byte)installation._Country) { InvClient._DeliveryCountry = installation._Country; } } } else { DCAccount deb; bool UseDebAddress; if (InvClient._DeliveryAccount != null) { deb = (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DeliveryAccount); UseDebAddress = true; } else { deb = client ?? (DCAccount)Comp.GetCache(typeof(Debtor), api)?.Get(InvClient._DCAccount); UseDebAddress = false; } if (deb != null) { if (deb._DeliveryAddress1 != null) { InvClient._DeliveryName = deb._DeliveryName; InvClient._DeliveryAddress1 = deb._DeliveryAddress1; InvClient._DeliveryAddress2 = deb._DeliveryAddress2; InvClient._DeliveryAddress3 = deb._DeliveryAddress3; InvClient._DeliveryZipCode = deb._DeliveryZipCode; InvClient._DeliveryCity = deb._DeliveryCity; InvClient._DeliveryCountry = deb._DeliveryCountry; } else if (UseDebAddress) { InvClient._DeliveryName = deb._Name; InvClient._DeliveryAddress1 = deb._Address1; InvClient._DeliveryAddress2 = deb._Address2; InvClient._DeliveryAddress3 = deb._Address3; InvClient._DeliveryZipCode = deb._ZipCode; InvClient._DeliveryCity = deb._City; if (Comp._Country != (byte)deb._Country) { InvClient._DeliveryCountry = deb._Country; } } } } }