async private Task <DCPreviousAddressClient> GetPreviousAddressForInvoice(DCInvoiceClient invClient) { if (invClient == null || crudApi == null) { return(null); } DCPreviousAddressClient selectedDateInvoiceAddr = null; var propvaluePairList = new System.Collections.Generic.List <PropValuePair>() { PropValuePair.GenereteWhereElements("DateChange", invClient.Date, CompareOperator.GreaterThan) }; var previousAddresses = await crudApi.Query <DCPreviousAddressClient>(invClient, propvaluePairList); if (previousAddresses != null && previousAddresses.Length > 0) { selectedDateInvoiceAddr = previousAddresses.FirstOrDefault(); } return(selectedDateInvoiceAddr); }
/// <summary> /// Method to Update Properties for Print Report /// </summary> /// <returns></returns> async public Task <bool> InstantiateFields() { try { var Comp = crudApi.CompanyEntity; var debtorInvoiceLineUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceLines), Comp); var debtorInvoiceClientUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceClient), Comp); DCInvoice dcInv; if (!isRePrint) { var invApi = new InvoiceAPI(crudApi); var invoiceLIneInstance = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines; dcInv = debtorInvoice; InvTransInvoiceLines = (DebtorInvoiceLines[])await invApi.GetInvoiceLines(dcInv, invoiceLIneInstance); PreviousAddressClient = isMultipleInvoicePrint ? LayoutPrintReport.GetPreviousAddressClientForInvoice(previousAddressLookup, debtorInvoice) : await LayoutPrintReport.GetPreviousAddressClientForInvoice(dcInv, crudApi); } else { dcInv = invoicePostingResult.Header; if (invoicePostingResult?.Lines != null && invoicePostingResult.Lines.Count() > 0) { var linesCount = invoicePostingResult.Lines.Count(); var lines = invoicePostingResult.Lines; InvTransInvoiceLines = Array.CreateInstance(debtorInvoiceLineUserType, linesCount) as DebtorInvoiceLines[]; int i = 0; foreach (var invtrans in invoicePostingResult.Lines) { DebtorInvoiceLines debtorInvoiceLines; if (invtrans.GetType() != debtorInvoiceLineUserType) { debtorInvoiceLines = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines; StreamingManager.Copy(invtrans, debtorInvoiceLines); } else { debtorInvoiceLines = invtrans as DebtorInvoiceLines; } InvTransInvoiceLines[i++] = debtorInvoiceLines; } } } //For Getting User-Fields for DebtorInvoice DebtorInvoiceClient debtorInvoiceClientUser; if (dcInv.GetType() != debtorInvoiceClientUserType) { debtorInvoiceClientUser = Activator.CreateInstance(debtorInvoiceClientUserType) as DebtorInvoiceClient; StreamingManager.Copy(dcInv, debtorInvoiceClientUser); } else { debtorInvoiceClientUser = dcInv as DebtorInvoiceClient; } DebtorInvoice = debtorInvoiceClientUser; //For Getting User fields for Debtor var debtorClietUserType = ReportUtil.GetUserType(typeof(DebtorClient), Comp); var debtorClientUser = Activator.CreateInstance(debtorClietUserType) as DebtorClient; var dcCache = Comp.GetCache(typeof(Uniconta.DataModel.Debtor)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.Debtor)); var debtor = dcCache.Get(DebtorInvoice._DCAccount); if (debtor != null) { StreamingManager.Copy((UnicontaBaseEntity)debtor, debtorClientUser); } else if (DebtorInvoice._Prospect != 0) { //Check for Prospect. Create a Debtor for Prospect var prosCache = Comp.GetCache(typeof(Uniconta.DataModel.CrmProspect)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.CrmProspect)); var prospect = prosCache?.Get(DebtorInvoice._Prospect) as CrmProspect; if (prospect != null) { debtorClientUser.CopyFrom(prospect); } } if (PreviousAddressClient != null) //Setting the Previous Address if Exist for current invoice { debtorClientUser._Name = PreviousAddressClient._Name; debtorClientUser._Address1 = PreviousAddressClient._Address1; debtorClientUser._Address2 = PreviousAddressClient._Address2; debtorClientUser._Address3 = PreviousAddressClient._Address3; debtorClientUser._City = PreviousAddressClient._City; debtorClientUser._ZipCode = PreviousAddressClient._ZipCode; } //to Contact listing for the current debtor if (Comp.Contacts) { var ContactsCache = Comp.GetCache(typeof(Uniconta.DataModel.Contact)) ?? await crudApi.LoadCache(typeof(Uniconta.DataModel.Contact)).ConfigureAwait(false); var contactCacheFilter = new ContactCacheFilter(ContactsCache, debtorClientUser.__DCType(), debtorClientUser._Account); if (contactCacheFilter.Any()) { try { debtorClientUser.Contacts = contactCacheFilter.Cast <ContactClient>().ToArray(); } catch { } } } Debtor = debtorClientUser; if (dcInv._Installation != null && Comp.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) == null) { await Comp.LoadCache(typeof(Uniconta.DataModel.WorkInstallation), crudApi); } UnicontaClient.Pages.DebtorOrders.SetDeliveryAdress(debtorInvoiceClientUser, debtorClientUser, crudApi); debtorInvoiceClientUser.SetInvoiceAddress(debtorClientUser); /*In case debtor order is null, fill from DCInvoice*/ if (DebtorOrder == null) { var debtorOrderUserType = ReportUtil.GetUserType(typeof(DebtorOrderClient), Comp); var debtorOrderUser = Activator.CreateInstance(debtorOrderUserType) as DebtorOrderClient; debtorOrderUser.CopyFrom(debtorInvoiceClientUser, debtorClientUser); DebtorOrder = debtorOrderUser; } Company = Utility.GetCompanyClientUserInstance(Comp); var InvCache = Comp.GetCache(typeof(InvItem)) ?? await crudApi.LoadCache(typeof(InvItem)); CompanyLogo = await Uniconta.ClientTools.Util.UtilDisplay.GetLogo(crudApi); Language lang = ReportGenUtil.GetLanguage(debtorClientUser, Comp); InvTransInvoiceLines = LayoutPrintReport.SetInvTransLines(DebtorInvoice, InvTransInvoiceLines, InvCache, crudApi, debtorInvoiceLineUserType, lang, false); //Setting ReportName and Version var invoiceNumber = DebtorInvoice._InvoiceNumber; var lineTotal = DebtorInvoice._LineTotal; IsCreditNote = (lineTotal < -0.0001d); ReportName = layoutType != CompanyLayoutType.Invoice ? layoutType.ToString() : invoiceNumber == 0 ? IsCreditNote ? "ProformaCreditNote" : "ProformaInvoice" : IsCreditNote ? "Creditnote" : "Invoice"; MessageClient = isMultipleInvoicePrint ? LayoutPrintReport.GetDebtorMessageClient(debtorMessageLookup, lang, GetDebtorEmailType()) : await Utility.GetDebtorMessageClient(crudApi, lang, GetDebtorEmailType()); var _LayoutGroup = DebtorInvoice._LayoutGroup ?? Debtor._LayoutGroup; if (_LayoutGroup != null) { var cache = crudApi.GetCache(typeof(DebtorLayoutGroup)) ?? await crudApi.LoadCache(typeof(DebtorLayoutGroup)); var layClient = (DebtorLayoutGroup)cache.Get(_LayoutGroup); layClient?.SetCompanyBank(Company); } return(true); } catch (Exception ex) { crudApi?.ReportException(ex, "Error Occured in DebtorInvoicePrintReport"); return(false); } }
/// <summary> /// Method to Update Properties for Print Report /// </summary> /// <returns></returns> async public Task <bool> InstantiateFields() { try { var Comp = crudApi.CompanyEntity; var debtorInvoiceLineUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceLines), Comp); var debtorInvoiceClientUserType = ReportUtil.GetUserType(typeof(DebtorInvoiceClient), Comp); DCPreviousAddressClient previousAddressClient = null; DCInvoiceClient dcInv; if (!isRePrint) { var invApi = new InvoiceAPI(crudApi); var invoiceLIneInstance = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines; dcInv = debtorInvoice; InvTransInvoiceLines = (DebtorInvoiceLines[])await invApi.GetInvoiceLines(dcInv, invoiceLIneInstance); previousAddressClient = await GetPreviousAddressForInvoice(dcInv); } else { dcInv = (DCInvoiceClient)invoicePostingResult.Header; var linesCount = invoicePostingResult.Lines.Count(); if (linesCount > 0) { var lines = invoicePostingResult.Lines; InvTransInvoiceLines = Array.CreateInstance(debtorInvoiceLineUserType, linesCount) as DebtorInvoiceLines[]; int i = 0; foreach (var invtrans in invoicePostingResult.Lines) { DebtorInvoiceLines debtorInvoiceLines; if (invtrans.GetType() != debtorInvoiceLineUserType) { debtorInvoiceLines = Activator.CreateInstance(debtorInvoiceLineUserType) as DebtorInvoiceLines; StreamingManager.Copy(invtrans, debtorInvoiceLines); } else { debtorInvoiceLines = invtrans as DebtorInvoiceLines; } InvTransInvoiceLines[i++] = debtorInvoiceLines; } } } //For Getting User-Fields for DebtorInvoice DebtorInvoiceClient debtorInvoiceClientUser; if (dcInv.GetType() != debtorInvoiceClientUserType) { debtorInvoiceClientUser = Activator.CreateInstance(debtorInvoiceClientUserType) as DebtorInvoiceClient; StreamingManager.Copy(dcInv, debtorInvoiceClientUser); } else { debtorInvoiceClientUser = dcInv as DebtorInvoiceClient; } DebtorInvoice = debtorInvoiceClientUser; //For Getting User fields for Debtor var debtorClietUserType = ReportUtil.GetUserType(typeof(DebtorClient), Comp); var debtorClientUser = Activator.CreateInstance(debtorClietUserType) as DebtorClient; var dcCache = Comp.GetCache(typeof(Uniconta.DataModel.Debtor)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.Debtor), crudApi); var debtor = dcCache.Get(DebtorInvoice._DCAccount); if (debtor != null) { StreamingManager.Copy((UnicontaBaseEntity)debtor, debtorClientUser); } else if (DebtorInvoice._Prospect != 0) { //Check for Prospect. Create a Debtor for Prospect var prosCache = Comp.GetCache(typeof(Uniconta.DataModel.CrmProspect)) ?? await Comp.LoadCache(typeof(Uniconta.DataModel.CrmProspect), crudApi); var prospect = prosCache?.Get(DebtorInvoice._Prospect) as CrmProspect; if (prospect != null) { debtorClientUser.CopyFrom(prospect); } } if (previousAddressClient != null) //Setting the Previous Address if Exist for current invoice { debtorClientUser._Name = previousAddressClient._Name; debtorClientUser._Address1 = previousAddressClient._Address1; debtorClientUser._Address2 = previousAddressClient._Address2; debtorClientUser._Address3 = previousAddressClient._Address3; debtorClientUser._City = previousAddressClient._City; debtorClientUser._ZipCode = previousAddressClient._ZipCode; } Debtor = debtorClientUser; if (dcInv._Installation != null && Comp.GetCache(typeof(Uniconta.DataModel.WorkInstallation)) == null) { await Comp.LoadCache(typeof(Uniconta.DataModel.WorkInstallation), crudApi); } UnicontaClient.Pages.DebtorOrders.SetDeliveryAdress(debtorInvoiceClientUser, debtorClientUser, crudApi); debtorInvoiceClientUser.SetInvoiceAddress(debtorClientUser); Company = Utility.GetCompanyClientUserInstance(Comp); var InvCache = Comp.GetCache(typeof(InvItem)) ?? await Comp.LoadCache(typeof(InvItem), crudApi); CompanyLogo = await Uniconta.ClientTools.Util.UtilDisplay.GetLogo(crudApi); Language lang = ReportGenUtil.GetLanguage(debtorClientUser, Comp); InvTransInvoiceLines = LayoutPrintReport.SetInvTransLines(DebtorInvoice, InvTransInvoiceLines, InvCache, debtorInvoiceLineUserType, lang, false); //Setting ReportName and Version var invoiceNumber = DebtorInvoice._InvoiceNumber; var lineTotal = DebtorInvoice._LineTotal; IsCreditNote = (lineTotal < -0.0001d); ReportName = layoutType != CompanyLayoutType.Invoice ? layoutType.ToString() : invoiceNumber == 0 ? "ProformaInvoice" : IsCreditNote ? "Creditnote" : "Invoice"; MessageClient = await GetMessageClient(lang); return(true); } catch (Exception ex) { crudApi?.ReportException(ex, "Error Occured in DebtorInvoicePrintReport"); return(false); } }