protected string PickAddressError <TFieldSource>(IAddressBase address) where TFieldSource : IBqlField { if (typeof(TFieldSource) == typeof(SOOrder.shipAddressID)) { return(PXSelect <SOOrder, Where <SOOrder.shipAddressID, Equal <Required <Address.addressID> > > > .SelectWindowed(Base, 0, 1, ((SOAddress)address).AddressID).First().GetItem <SOOrder>() .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <SOOrder>(), new EntityHelper(Base).GetRowID(e)))); } if (typeof(TFieldSource) == typeof(Vendor.defLocationID)) { return(PXSelectReadonly2 <Vendor, InnerJoin <Location, On <Location.locationID, Equal <Vendor.defLocationID> > >, Where <Location.defAddressID, Equal <Required <Address.addressID> > > > .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <Vendor>() .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <Vendor>(), new EntityHelper(Base).GetRowID(e)))); } if (typeof(TFieldSource) == typeof(INSite.addressID)) { return(PXSelectReadonly <INSite, Where <INSite.addressID, Equal <Required <Address.addressID> > > > .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <INSite>() .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <INSite>(), new EntityHelper(Base).GetRowID(e)))); } if (typeof(TFieldSource) == typeof(BAccountR.defAddressID)) { return(PXSelectReadonly <BAccountR, Where <BAccountR.defAddressID, Equal <Required <Address.addressID> > > > .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <BAccountR>() .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <BAccountR>(), new EntityHelper(Base).GetRowID(e)))); } throw new ArgumentOutOfRangeException("Unknown address source used"); }
public bool ValidateAddress(IAddressBase aAddress, out bool isValid, Dictionary <PXAddressValidator.Fields, string> messages) { isValid = false; AvaAddress.ValidateRequest request = new AvaAddress.ValidateRequest(); request.Address = FromAddress(aAddress); AvaAddress.ValidateResult result = this._service.Validate(request); isValid = (result.ResultCode == Avalara.AvaTax.Adapter.SeverityLevel.Success || result.ResultCode == Avalara.AvaTax.Adapter.SeverityLevel.Warning); if (result.ResultCode != Avalara.AvaTax.Adapter.SeverityLevel.Success) { foreach (Avalara.AvaTax.Adapter.Message iMsg in result.Messages) { PXAddressValidator.Fields id = GetExtFieldName(iMsg.RefersTo); messages.Add(id, String.IsNullOrEmpty(iMsg.Details) ? (String.IsNullOrEmpty(iMsg.Summary)? (String.IsNullOrEmpty(iMsg.Source)? Messages.AvalaraAVSUnknownError:iMsg.Source) :iMsg.Summary) :iMsg.Details); } } if (isValid && result.Addresses.Count > 0) { Copy(aAddress, result.Addresses[0]); } return(true); }
public virtual IAddressBase GetFromAddress(ARInvoice invoice, ARTran tran, GetFromAddressLineDelegate del) { int?SOID = GetSOIDRelated(tran); if (SOID != null && tran.SiteID == null) { IAddressBase returnAddress = null; returnAddress = PXSelectJoin <FSAddress, InnerJoin < FSBranchLocation, On <FSBranchLocation.branchLocationAddressID, Equal <FSAddress.addressID> >, InnerJoin <FSServiceOrder, On <FSServiceOrder.branchLocationID, Equal <FSBranchLocation.branchLocationID> > > >, Where < FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > > .Select(Base, SOID) .RowCast <FSAddress>() .FirstOrDefault(); return(returnAddress); } return(del(invoice, tran)); }
public static string ExtractStreetAddress(IAddressBase aAddress) { var res = new[] { aAddress.AddressLine1, aAddress.AddressLine2, aAddress.AddressLine3 } .Where(i => !string.IsNullOrWhiteSpace(i)) .Aggregate(string.Empty, (cur, next) => string.IsNullOrEmpty(cur) ? next : cur + ", " + next); return(res); }
private IAddressBase ValidAddressFrom <TFieldSource>(IAddressBase address) where TFieldSource : IBqlField { if (!string.IsNullOrEmpty(address.PostalCode)) { return(address); } throw new PXException(PickAddressError <TFieldSource>(address)); }
protected IAddressBase ValidAddressFrom <TFieldSource>(IAddressBase address) where TFieldSource : IBqlField { if (!IsEmptyAddress(address)) { return(address); } throw new PXException(PickAddressError <TFieldSource>(address)); }
private static void Copy(IAddressBase dest, AvaAddress.ValidAddress src) { dest.City = src.City; dest.CountryID = src.Country; dest.AddressLine1 = src.Line1; dest.AddressLine2 = src.Line2; dest.AddressLine3 = src.Line3; dest.PostalCode = src.PostalCode; dest.State = src.Region; }
private static AvaAddress.Address FromAddress(IAddressBase address) { AvaAddress.Address result = new AvaAddress.Address(); result.City = address.City; result.Country = address.CountryID; result.Line1 = address.AddressLine1; result.Line2 = address.AddressLine2; result.Line3 = address.AddressLine3; result.PostalCode = address.PostalCode; result.Region = address.State; return(result); }
public static TaxAddress ConvertTaxAddress(IAddressBase address) { var result = new TaxAddress { Country = address.CountryID, Region = address.State, City = address.City, PostalCode = address.PostalCode, AddressLine1 = address.AddressLine1, AddressLine2 = address.AddressLine2, AddressLine3 = address.AddressLine3, }; return(result); }
protected virtual IAddressBase MapAddress(DocumentAddress source, IAddressBase target) { if (source is null) { throw new ArgumentNullException(nameof(source)); } if (target is null) { throw new ArgumentNullException(nameof(target)); } target.AddressLine1 = source.AddressLine1; target.AddressLine2 = source.AddressLine2; target.City = source.City; target.CountryID = source.CountryID; target.State = source.State; target.PostalCode = source.PostalCode; return(target); }
public static string ExtractStreetAddress(IAddressBase aAddress) { string result = aAddress.AddressLine1; if (string.IsNullOrEmpty(aAddress.AddressLine1)) { if (!string.IsNullOrEmpty(result)) { result += " "; } result += aAddress.AddressLine1; } if (string.IsNullOrEmpty(aAddress.AddressLine2)) { if (!string.IsNullOrEmpty(result)) { result += " "; } result += aAddress.AddressLine2; } return(result); }
public virtual IAddressBase GetToAddress(SOOrder order, SOLine line, GetToAddressLineDelegate del) { int?SOID = GetSOIDRelated(line); if (SOID != null) { IAddressBase returnAddress = null; returnAddress = PXSelectJoin <FSAddress, InnerJoin <FSServiceOrder, On <FSServiceOrder.serviceOrderAddressID, Equal <FSAddress.addressID> > >, Where < FSServiceOrder.sOID, Equal <Required <FSServiceOrder.sOID> > > > .Select(Base, SOID) .RowCast <FSAddress>() .FirstOrDefault(); return(returnAddress); } return(del(order, line)); }
protected virtual IAddressBase GetFromAddress(FSServiceOrder order, FSAppointmentDet line) { IAddressBase returnAddress = null; if (line.SiteID != null) { returnAddress = PXSelectJoin <Address, InnerJoin <INSite, On <Address.addressID, Equal <INSite.addressID> > >, Where < INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(Base, line.SiteID) .RowCast <Address>() .FirstOrDefault(); } if (returnAddress == null) { returnAddress = GetFromAddress(order); } return(returnAddress); }
private IAddressBase GetDropShipDestinationAddress(ARTran tran, SOLine soLine) { if (soLine != null && tran.SOOrderLineNbr != null) { Boolean isDropShip = soLine.POCreate == true && soLine.POSource == INReplenishmentSource.DropShipToOrder; IAddressBase dropShipAddress = isDropShip ? PXSelectJoin <PO.POAddress, InnerJoin <PO.POOrder, On <PO.POOrder.shipAddressID, Equal <PO.POAddress.addressID> >, InnerJoin <PO.POReceiptLine, On <PO.POReceiptLine.pOType, Equal <PO.POOrder.orderType>, And <PO.POReceiptLine.pONbr, Equal <PO.POOrder.orderNbr> > > > >, Where <PO.POReceiptLine.receiptNbr, Equal <Current <ARTran.sOShipmentNbr> >, And <PO.POReceiptLine.lineNbr, Equal <Current <ARTran.sOShipmentLineNbr> > > > > .SelectSingleBound(Base, new[] { tran }) .RowCast <PO.POAddress>() .FirstOrDefault() : null; if (dropShipAddress != null) { return(dropShipAddress.With(ValidAddressFrom <PO.POOrder.shipAddressID>)); } } return(null); }
public virtual CommitTaxRequest BuildCommitTaxRequestWithFrt(ARInvoice invoice) { if (invoice == null) { throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException); } Customer cust = (Customer)Base.customer.View.SelectSingleBound(new object[] { invoice }); CR.Location loc = (CR.Location)Base.location.View.SelectSingleBound(new object[] { invoice }); CommitTaxRequest request = new CommitTaxRequest(); request.CompanyCode = Base1.CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID); request.CurrencyCode = invoice.CuryID; request.CustomerCode = cust.AcctCD; request.TaxRegistrationID = loc?.TaxRegistrationID; IAddressBase fromAddress = Base1.GetFromAddress(invoice); IAddressBase toAddress = Base1.GetToAddress(invoice); if (fromAddress == null) { throw new PXException(Messages.FailedGetFrom); } if (toAddress == null) { throw new PXException(Messages.FailedGetTo); } request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = $"AR.{invoice.DocType}.{invoice.RefNbr}"; request.DocDate = invoice.DocDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode <ARTran, ARTran.FK.Invoice.SameAsCurrent, ARTran.siteID>(invoice); request.CustomerUsageType = invoice.AvalaraCustomerUsageType; if (!string.IsNullOrEmpty(invoice.ExternalTaxExemptionNumber)) { request.ExemptionNo = invoice.ExternalTaxExemptionNumber; } request.DocType = Base1.GetTaxDocumentType(invoice); Sign sign = Base1.GetDocumentSign(invoice); PXSelectBase <ARTran> select = new PXSelectJoin <ARTran, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <ARTran.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <ARTran.accountID> > > >, Where <ARTran.tranType, Equal <Current <ARInvoice.docType> >, And <ARTran.refNbr, Equal <Current <ARInvoice.refNbr> >, And <Where <ARTran.lineType, NotEqual <SOLineType.discount>, Or <ARTran.lineType, IsNull> > > > >, OrderBy <Asc <ARTran.tranType, Asc <ARTran.refNbr, Asc <ARTran.lineNbr> > > > >(Base); request.Discount = Base.Document.Current.CuryDiscTot.GetValueOrDefault(); DateTime?taxDate = invoice.OrigDocDate; bool applyRetainage = Base.ARSetup.Current?.RetainTaxes != true && invoice.IsOriginalRetainageDocument(); /// <summary> /// Add the following condition and logic per Jira [IP-23] /// </summary>> string taxCategory = (Base as SOInvoiceEntry).FreightDetails.Current?.TaxCategoryID; if (invoice.CuryFreightTot > 0 && GL.Branch.PK.Find(Base, Base.Accessinfo.BranchID).CountryID == Country_US && invoice.TaxZoneID == TaxCloud && !string.IsNullOrEmpty(taxCategory)) { var line = new TaxCartItem(); line.Index = short.MinValue; line.Quantity = 1; line.UOM = "EA"; line.Amount = sign * invoice.CuryFreightTot.GetValueOrDefault(); line.Description = PXMessages.LocalizeNoPrefix(SO.Messages.FreightDesc); line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = "N/A"; line.Discounted = false; line.TaxCode = taxCategory; request.CartItems.Add(line); } foreach (PXResult <ARTran, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { invoice })) { ARTran tran = (ARTran)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = sign * (tran.CuryTranAmt.GetValueOrDefault() + (applyRetainage ? tran.CuryRetainageAmt.GetValueOrDefault() : 0m)); line.Description = tran.TranDesc; line.DestinationAddress = AddressConverter.ConvertTaxAddress(Base1.GetToAddress(invoice, tran)); line.OriginAddress = AddressConverter.ConvertTaxAddress(Base1.GetFromAddress(invoice, tran)); line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.Qty.GetValueOrDefault()); line.UOM = tran.UOM; line.Discounted = tran.LineType != SOLineType.Freight && request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; line.CustomerUsageType = tran.AvalaraCustomerUsageType; if (tran.OrigInvoiceDate != null) { taxDate = tran.OrigInvoiceDate; } request.CartItems.Add(line); } if (applyRetainage) { var line = new TaxCartItem(); line.Index = invoice.LineCntr.GetValueOrDefault() + 1; line.Amount = Sign.Minus * sign * invoice.CuryLineRetainageTotal.GetValueOrDefault(); line.Description = PXMessages.LocalizeFormatNoPrefix(AP.Messages.RetainageForTransactionDescription, GetLabel.For <ARDocType>(invoice.DocType), invoice.RefNbr); line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = "Retainage"; line.Discounted = false; line.NonTaxable = true; request.CartItems.Add(line); } if ((invoice.DocType == ARDocType.CreditMemo || invoice.DocType == ARDocType.CashReturn) && invoice.OrigDocDate != null) { request.TaxOverride.Reason = Messages.ReturnReason; request.TaxOverride.TaxDate = taxDate.Value; request.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; sign = Sign.Minus; } return(request); }
protected virtual GetTaxRequest BuildGetTaxRequestUnbilled(POOrder order) { if (order == null) { throw new PXArgumentException(nameof(order)); } Vendor vend = (Vendor)Base.vendor.View.SelectSingleBound(new object[] { order }); Location loc = (Location)Base.location.View.SelectSingleBound(new object[] { order }); IAddressBase fromAddress = GetFromAddress(order); IAddressBase toAddress = GetToAddress(order); if (fromAddress == null) { throw new PXException(Messages.FailedGetFromAddressSO); } if (toAddress == null) { throw new PXException(Messages.FailedGetToAddressSO); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(order.TaxZoneID, order.BranchID); request.CurrencyCode = order.CuryID; request.CustomerCode = vend.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = string.Format("PO.{0}.{1}", order.OrderType, order.OrderNbr); request.DocDate = order.OrderDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(order); int mult = 1; request.CustomerUsageType = loc.CAvalaraCustomerUsageType; if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.PurchaseOrder; PXSelectBase <POLine> select = new PXSelectJoin <POLine, LeftJoin <InventoryItem, On <POLine.FK.InventoryItem>, LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >, Where <POLine.orderType, Equal <Current <POOrder.orderType> >, And <POLine.orderNbr, Equal <Current <POOrder.orderNbr> > > >, OrderBy <Asc <POLine.lineNbr> > >(Base); foreach (PXResult <POLine, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order })) { POLine tran = (POLine)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; if (tran.UnbilledAmt > 0) { var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = mult * tran.CuryUnbilledAmt.GetValueOrDefault(); line.Description = tran.TranDesc; line.OriginAddress = AddressConverter.ConvertTaxAddress(GetFromAddress(order, tran)); line.DestinationAddress = AddressConverter.ConvertTaxAddress(GetToAddress(order, tran)); line.ItemCode = item.InventoryCD; line.Quantity = tran.BaseUnbilledQty.GetValueOrDefault(); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } } return(request); }
protected static GetTaxRequest BuildGetTaxRequest(OpportunityMaint rg, CROpportunity order) { if (order == null) { throw new PXArgumentException(ErrorMessages.ArgumentNullException); } BAccount cust = (BAccount)PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Select(rg, order.BAccountID); Location loc = (Location)PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > . Select(rg, order.BAccountID, order.LocationID); IAddressBase addressFrom = GetFromAddress(rg); IAddressBase addressTo = GetToAddress(rg, order); if (addressFrom == null) { throw new PXException(Messages.FailedGetFromAddressSO); } if (addressTo == null) { throw new PXException(Messages.FailedGetToAddressSO); } var avalaraSetup = (TXAvalaraSetup)PXSetupOptional <TXAvalaraSetup> .Select(rg); GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = AvalaraMaint.CompanyCodeFromBranch(rg, rg.Accessinfo.BranchID); request.CurrencyCode = order.CuryID; request.CustomerCode = cust.AcctCD; request.OriginAddress = AvalaraMaint.FromAddress(addressFrom); request.DestinationAddress = AvalaraMaint.FromAddress(addressTo); request.DetailLevel = DetailLevel.Summary; request.DocCode = string.Format("CR.{0}", order.OpportunityID); request.DocDate = order.CloseDate.GetValueOrDefault(); int mult = 1; if (!string.IsNullOrEmpty(loc.CAvalaraCustomerUsageType)) { request.CustomerUsageType = loc.CAvalaraCustomerUsageType; } if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = DocumentType.SalesOrder; PXSelectBase <CROpportunityProducts> select = new PXSelectJoin <CROpportunityProducts, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CROpportunityProducts.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >, Where <CROpportunityProducts.cROpportunityID, Equal <Current <CROpportunity.opportunityID> > >, OrderBy <Asc <CROpportunityProducts.cROpportunityProductID> > >(rg); foreach (PXResult <CROpportunityProducts, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order })) { CROpportunityProducts tran = (CROpportunityProducts)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; Line line = new Line(); line.No = Convert.ToString(tran.CROpportunityProductID); line.Amount = mult * tran.CuryAmount.GetValueOrDefault(); line.Description = tran.TransactionDescription; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Qty = Math.Abs(Convert.ToDouble(tran.Qty.GetValueOrDefault())); line.Discounted = request.Discount > 0; line.TaxIncluded = avalaraSetup.IsInclusiveTax == true; if (avalaraSetup != null && avalaraSetup.SendRevenueAccount == true) { line.RevAcct = salesAccount.AccountCD; } line.TaxCode = tran.TaxCategoryID; request.Lines.Add(line); } return(request); }
protected GetTaxRequest BuildGetTaxRequestWithFRTCate <TLineAmt, TLineQty, TDocDiscount>(SOOrder order, string docCode, string debugMethodName) where TLineAmt : IBqlField where TLineQty : IBqlField where TDocDiscount : IBqlField { Stopwatch sw = new Stopwatch(); sw.Start(); Debug.Indent(); if (order == null) { throw new PXArgumentException(nameof(order)); } Customer cust = (Customer)Base.customer.View.SelectSingleBound(new object[] { order }); Location loc = (Location)Base.location.View.SelectSingleBound(new object[] { order }); IAddressBase fromAddress = GetFromAddress(order); IAddressBase toAddress = GetToAddress(order); Debug.Print($"{DateTime.Now.TimeOfDay} Select Customer, Location, Addresses in {sw.ElapsedMilliseconds} millisec"); if (fromAddress == null) { throw new PXException(Messages.FailedGetFromAddressSO); } if (toAddress == null) { throw new PXException(Messages.FailedGetToAddressSO); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = Base1.CompanyCodeFromBranch(order.TaxZoneID, order.BranchID); request.CurrencyCode = order.CuryID; request.CustomerCode = cust.AcctCD; request.TaxRegistrationID = loc?.TaxRegistrationID; request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = docCode; request.DocDate = order.OrderDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode <SOLine, SOLine.FK.Order.SameAsCurrent, SOLine.siteID>(order); Sign docSign = Sign.Plus; request.CustomerUsageType = order.AvalaraCustomerUsageType; if (!string.IsNullOrEmpty(order.ExternalTaxExemptionNumber)) { request.ExemptionNo = order.ExternalTaxExemptionNumber; } SOOrderType orderType = (SOOrderType)Base.soordertype.View.SelectSingleBound(new object[] { order }); if (orderType.DefaultOperation == SOOperation.Receipt) { request.DocType = TaxDocumentType.ReturnOrder; docSign = Sign.Minus; } else { request.DocType = TaxDocumentType.SalesOrder; } PXSelectBase <SOLine> select = new PXSelectJoin <SOLine, LeftJoin <InventoryItem, On <SOLine.FK.InventoryItem>, LeftJoin <Account, On <Account.accountID, Equal <SOLine.salesAcctID> > > >, Where <SOLine.orderType, Equal <Current <SOOrder.orderType> >, And <SOLine.orderNbr, Equal <Current <SOOrder.orderNbr> > > >, OrderBy <Asc <SOLine.orderType, Asc <SOLine.orderNbr, Asc <SOLine.lineNbr> > > > >(Base); PXCache documentCache = Base.Caches[typeof(SOOrder)]; request.Discount = (documentCache.GetValue <TDocDiscount>(order) as decimal?) ?? 0m; Stopwatch sw2 = new Stopwatch(); sw2.Start(); // Add additional condition to skip the calculation including the freight amount. Per YJ's request. if (order.CuryFreightTot > 0 && !string.IsNullOrEmpty(order.FreightTaxCategoryID)) { var line = new TaxCartItem(); line.Index = short.MinValue; line.Quantity = 1; line.UOM = "EA"; line.Amount = docSign * order.CuryFreightTot.GetValueOrDefault(); line.Description = PXMessages.LocalizeNoPrefix(Messages.FreightDesc); line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = "N/A"; line.Discounted = false; line.TaxCode = order.FreightTaxCategoryID; request.CartItems.Add(line); } PXCache lineCache = Base.Caches[typeof(SOLine)]; foreach (PXResult <SOLine, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order })) { SOLine tran = (SOLine)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; bool lineIsDiscounted = request.Discount > 0m && ((tran.DocumentDiscountRate ?? 1m) != 1m || (tran.GroupDiscountRate ?? 1m) != 1m); var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; decimal lineAmount = (lineCache.GetValue <TLineAmt>(tran) as decimal?) ?? 0m; decimal lineQty = (lineCache.GetValue <TLineQty>(tran) as decimal?) ?? 0m; line.Amount = orderType.DefaultOperation != tran.Operation ? Sign.Minus * docSign * lineAmount : docSign * lineAmount; line.Description = tran.TranDesc; line.DestinationAddress = AddressConverter.ConvertTaxAddress(Base1.GetToAddress(order, tran)); line.OriginAddress = AddressConverter.ConvertTaxAddress(Base1.GetFromAddress(order, tran)); line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(lineQty); line.UOM = tran.UOM; line.Discounted = lineIsDiscounted; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; line.CustomerUsageType = tran.AvalaraCustomerUsageType; if (tran.Operation == SOOperation.Receipt && tran.InvoiceDate != null) { line.TaxOverride.Reason = Messages.ReturnReason; line.TaxOverride.TaxDate = tran.InvoiceDate.Value; line.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; } request.CartItems.Add(line); } sw2.Stop(); Debug.Print($"{DateTime.Now.TimeOfDay} Select detail lines in {sw2.ElapsedMilliseconds} millisec."); Debug.Unindent(); sw.Stop(); Debug.Print($"{DateTime.Now.TimeOfDay} {debugMethodName}() in {sw.ElapsedMilliseconds} millisec."); return(request); }
public static bool IsEmptyAddress(IAddressBase address) => string.IsNullOrEmpty(address?.PostalCode);
protected virtual GetTaxRequest BuildGetTaxRequest(CROpportunity order) { if (order == null) { throw new PXArgumentException(nameof(order)); } BAccount cust = (BAccount)PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Select(Base, order.BAccountID); Location loc = (Location)PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > . Select(Base, order.BAccountID, order.LocationID); IAddressBase addressFrom = GetFromAddress(); IAddressBase addressTo = GetToAddress(order); if (addressFrom == null) { throw new PXException(Messages.FailedGetFromAddressCR); } if (addressTo == null) { throw new PXException(Messages.FailedGetToAddressCR); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(order.TaxZoneID, Base.Accessinfo.BranchID); request.CurrencyCode = order.CuryID; request.CustomerCode = cust?.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(addressFrom); request.DestinationAddress = AddressConverter.ConvertTaxAddress(addressTo); request.DocCode = $"CR.{order.OpportunityID}"; request.DocDate = order.CloseDate.GetValueOrDefault(); request.Discount = order.CuryLineDocDiscountTotal.GetValueOrDefault(); int mult = 1; if (loc != null) { request.CustomerUsageType = loc.CAvalaraCustomerUsageType; } if (!string.IsNullOrEmpty(loc?.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.SalesOrder; PXSelectBase <CROpportunityProducts> select = new PXSelectJoin <CROpportunityProducts, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CROpportunityProducts.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >, Where <CROpportunityProducts.quoteID, Equal <Current <CROpportunity.quoteNoteID> > >, OrderBy <Asc <CROpportunityProducts.lineNbr> > >(Base); foreach (PXResult <CROpportunityProducts, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order })) { CROpportunityProducts tran = (CROpportunityProducts)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = mult * tran.CuryAmount.GetValueOrDefault(); line.Description = tran.Descr; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.Qty.GetValueOrDefault()); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }
protected virtual GetTaxRequest BuildGetTaxRequest(FSAppointment fsAppointment, FSServiceOrder order) { if (fsAppointment == null) { throw new PXArgumentException(nameof(fsAppointment)); } Customer cust = (Customer)Base.TaxCustomer.View.SelectSingleBound(new object[] { fsAppointment }); Location loc = (Location)Base.TaxLocation.View.SelectSingleBound(new object[] { fsAppointment }); IAddressBase fromAddress = GetFromAddress(order); IAddressBase toAddress = GetToAddress(order); if (fromAddress == null) { throw new PXException(PX.Objects.CR.Messages.FailedGetFromAddressCR); } if (toAddress == null) { throw new PXException(PX.Objects.CR.Messages.FailedGetToAddressCR); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(fsAppointment.TaxZoneID, fsAppointment.BranchID); request.CurrencyCode = fsAppointment.CuryID; request.CustomerCode = cust.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = string.Format("SO.{0}.{1}", fsAppointment.SrvOrdType, fsAppointment.RefNbr); request.DocDate = fsAppointment.ScheduledDateTimeBegin.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(fsAppointment); Sign sign = Sign.Plus; request.CustomerUsageType = loc.CAvalaraCustomerUsageType; if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } FSSrvOrdType srvOrdType = (FSSrvOrdType)Base.ServiceOrderTypeSelected.View.SelectSingleBound(new object[] { fsAppointment }); /*if (srvOrdType.DefaultOperation == SOOperation.Receipt) * { * request.DocType = TaxDocumentType.ReturnOrder; * sign = Sign.Minus; * * PXSelectBase<FSAppointmentDet> selectLineWithInvoiceDate = new PXSelect<FSAppointmentDet, * Where<FSAppointmentDet.srvOrdType, Equal<Required<FSAppointmentDet.srvOrdType>>, And<FSAppointmentDet.refNbr, Equal<Required<FSAppointmentDet.refNbr>>, * And<FSAppointmentDet.invoiceDate, IsNotNull>>>>(Base); * * FSAppointmentDet soLine = selectLineWithInvoiceDate.SelectSingle(order.SrvOrdType, order.RefNbr); * if (soLine != null && soLine.TranDate != null) * { * request.TaxOverride.Reason = PX.Objects.SO.Messages.ReturnReason; * request.TaxOverride.TaxDate = soLine.TranDate.Value; * request.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; * } * * } * else * {*/ request.DocType = TaxDocumentType.SalesOrder; /*}*/ /* We need InnerJoin with InventoryItem instead of LeftJoin */ /* because of instructions and comments lines */ PXSelectBase <FSAppointmentDet> select = new PXSelectJoin <FSAppointmentDet, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <FSAppointmentDet.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <FSAppointmentDet.acctID> > > >, Where <FSAppointmentDet.srvOrdType, Equal <Current <FSAppointment.srvOrdType> >, And <FSAppointmentDet.refNbr, Equal <Current <FSAppointment.refNbr> > > >, OrderBy <Asc <FSAppointmentDet.srvOrdType, Asc <FSAppointmentDet.refNbr, Asc <FSAppointmentDet.lineNbr> > > > >(Base); request.Discount = fsAppointment.CuryDiscTot.GetValueOrDefault(); foreach (PXResult <FSAppointmentDet, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { fsAppointment })) { FSAppointmentDet tran = (FSAppointmentDet)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; /*if (srvOrdType.DefaultOperation != tran.Operation) * line.Amount = Sign.Minus * sign * tran.CuryLineAmt.GetValueOrDefault(); * else * line.Amount = sign * tran.CuryLineAmt.GetValueOrDefault();*/ line.Amount = sign * tran.CuryBillableTranAmt.GetValueOrDefault(); line.Description = tran.TranDesc; line.DestinationAddress = AddressConverter.ConvertTaxAddress(GetToAddress(order, tran)); line.OriginAddress = AddressConverter.ConvertTaxAddress(GetFromAddress(order, tran)); line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.Qty.GetValueOrDefault()); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }
protected GetTaxRequest BuildGetTaxRequest(PMQuote quote) { if (quote == null) { throw new PXArgumentException(ErrorMessages.ArgumentNullException); } BAccount cust = (BAccount)PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Select(Base, quote.BAccountID); CR.Location loc = (CR.Location) PXSelect <CR.Location, Where <CR.Location.bAccountID, Equal <Required <CR.Location.bAccountID> >, And <CR.Location.locationID, Equal <Required <CR.Location.locationID> > > > > . Select(Base, quote.BAccountID, quote.LocationID); IAddressBase addressFrom = GetFromAddress(quote); IAddressBase addressTo = GetToAddress(quote); if (addressFrom == null) { throw new PXException(CR.Messages.FailedGetFromAddressCR); } if (addressTo == null) { throw new PXException(CR.Messages.FailedGetToAddressCR); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(quote.TaxZoneID, Base.Accessinfo.BranchID); request.CurrencyCode = quote.CuryID; request.CustomerCode = cust.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(addressFrom); request.DestinationAddress = AddressConverter.ConvertTaxAddress(addressTo); request.DocCode = string.Format("CR.{0}", quote.OpportunityID); request.DocDate = quote.DocumentDate.GetValueOrDefault(); request.Discount = quote.CuryLineDocDiscountTotal.GetValueOrDefault(); int mult = 1; if (!string.IsNullOrEmpty(loc.CAvalaraCustomerUsageType)) { request.CustomerUsageType = loc.CAvalaraCustomerUsageType; } if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.SalesOrder; var select = PXSelectJoin <CROpportunityProducts, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CROpportunityProducts.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >, Where <CROpportunityProducts.quoteID, Equal <Required <PMQuote.quoteID> > >, OrderBy <Asc <CROpportunityProducts.lineNbr> > > .Select(Base, quote.QuoteID); foreach (PXResult <CROpportunityProducts, InventoryItem, Account> res in select) { CROpportunityProducts tran = (CROpportunityProducts)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = mult * tran.CuryAmount.GetValueOrDefault(); line.Description = tran.Descr; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = tran.Qty.GetValueOrDefault(); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }
protected virtual CarrierBoxEx BuildCarrierBoxes(List <SOPackageInfoEx> list, IAddressBase origin, string method, CarrierPlugin plugin) { List <CarrierBox> boxes = new List <CarrierBox>(); foreach (SOPackageInfoEx boxInfo in list) { boxes.Add(BuildCarrierPackage(boxInfo, plugin)); } CarrierBoxEx result = new CarrierBoxEx(0, 0); result.Packages = boxes; result.Method = method; result.Origin = origin; return(result); }
protected virtual GetTaxRequest BuildGetTaxRequest(CAAdj invoice) { if (invoice == null) { throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID); request.CurrencyCode = invoice.CuryID; request.CustomerCode = "N/A"; IAddressBase fromAddress = GetToAddress(invoice); IAddressBase toAddress = fromAddress; if (fromAddress == null) { throw new PXException(Messages.FailedGetFrom); } if (toAddress == null) { throw new PXException(Messages.FailedGetTo); } request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = $"CA.{invoice.AdjRefNbr}"; request.DocDate = invoice.TranDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(invoice); Location branchLoc = GetBranchLocation(invoice); if (branchLoc != null) { request.CustomerUsageType = branchLoc.CAvalaraCustomerUsageType; request.ExemptionNo = branchLoc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.PurchaseInvoice; int mult = 1; if (invoice.DrCr == CADrCr.CADebit) { request.DocType = TaxDocumentType.SalesInvoice; } else { request.DocType = TaxDocumentType.PurchaseInvoice; } PXSelectBase <CASplit> select = new PXSelectJoin <CASplit, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <CASplit.inventoryID> > >, Where <CASplit.adjRefNbr, Equal <Current <CAAdj.adjRefNbr> > >, OrderBy <Asc <CASplit.adjRefNbr, Asc <CASplit.lineNbr> > > >(Base); foreach (PXResult <CASplit, InventoryItem> res in select.View.SelectMultiBound(new object[] { invoice })) { CASplit tran = (CASplit)res; InventoryItem item = (InventoryItem)res; var line = new TaxCartItem { Index = tran.LineNbr ?? 0, Amount = mult * tran.CuryTranAmt.GetValueOrDefault(), Description = tran.TranDesc, DestinationAddress = request.DestinationAddress, OriginAddress = request.OriginAddress, ItemCode = item.InventoryCD, Quantity = Math.Abs(tran.Qty.GetValueOrDefault()), Discounted = request.Discount > 0, TaxCode = tran.TaxCategoryID, }; request.CartItems.Add(line); } return(request); }
protected virtual GetTaxRequest BuildGetTaxRequest(ARCashSale invoice) { if (invoice == null) { throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException); } Customer cust = (Customer)Base.customer.View.SelectSingleBound(new object[] { invoice }); Location loc = (Location)Base.location.View.SelectSingleBound(new object[] { invoice }); GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID); request.CurrencyCode = invoice.CuryID; request.CustomerCode = cust.AcctCD; IAddressBase fromAddress = GetFromAddress(invoice); IAddressBase toAddress = GetToAddress(invoice); if (fromAddress == null) { throw new PXException(Messages.FailedGetFrom); } if (toAddress == null) { throw new PXException(Messages.FailedGetTo); } request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = $"AR.{invoice.DocType}.{invoice.RefNbr}"; request.DocDate = invoice.DocDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(invoice); request.CustomerUsageType = invoice.AvalaraCustomerUsageType; if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = GetTaxDocumentType(invoice); Sign sign = GetDocumentSign(invoice); PXSelectBase <ARTran> select = new PXSelectJoin <ARTran, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <ARTran.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <ARTran.accountID> > > >, Where <ARTran.tranType, Equal <Current <ARCashSale.docType> >, And <ARTran.refNbr, Equal <Current <ARCashSale.refNbr> >, And <Where <ARTran.lineType, NotEqual <SOLineType.discount>, Or <ARTran.lineType, IsNull> > > > >, OrderBy <Asc <ARTran.tranType, Asc <ARTran.refNbr, Asc <ARTran.lineNbr> > > > >(Base); request.Discount = GetDocDiscount().GetValueOrDefault(); DateTime?taxDate = invoice.OrigDocDate; foreach (PXResult <ARTran, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { invoice })) { ARTran tran = (ARTran)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = sign * tran.CuryTranAmt.GetValueOrDefault(); line.Description = tran.TranDesc; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.Qty.GetValueOrDefault()); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; if (tran.OrigInvoiceDate != null) { taxDate = tran.OrigInvoiceDate; } request.CartItems.Add(line); } if (invoice.DocType == ARDocType.CashReturn && invoice.OrigDocDate != null) { request.TaxOverride.Reason = Messages.ReturnReason; request.TaxOverride.TaxDate = taxDate.Value; request.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; } return(request); }
protected virtual GetTaxRequest BuildTaxRequest(APInvoice invoice) { if (invoice == null) { throw new PXArgumentException(nameof(invoice), ErrorMessages.ArgumentNullException); } Vendor vend = (Vendor)Base.vendor.View.SelectSingleBound(new object[] { invoice }); var request = new PX.TaxProvider.GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(invoice.TaxZoneID, invoice.BranchID); request.CurrencyCode = invoice.CuryID; request.CustomerCode = vend.AcctCD; IAddressBase fromAddress = GetFromAddress(invoice); IAddressBase toAddress = GetToAddress(invoice); if (fromAddress == null) { throw new PXException(Messages.FailedGetFrom); } if (toAddress == null) { throw new PXException(Messages.FailedGetTo); } request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = $"AP.{invoice.DocType}.{invoice.RefNbr}"; request.DocDate = invoice.DocDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(invoice); Location branchLoc = GetBranchLocation(invoice); if (branchLoc != null) { request.CustomerUsageType = branchLoc.CAvalaraCustomerUsageType; request.ExemptionNo = branchLoc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.PurchaseInvoice; int mult = 1; switch (invoice.DocType) { case APDocType.Invoice: case APDocType.CreditAdj: request.DocType = TaxDocumentType.PurchaseInvoice; break; case APDocType.DebitAdj: if (invoice.OrigDocDate != null) { request.TaxOverride.Reason = Messages.DebitAdjustmentReason; request.TaxOverride.TaxDate = invoice.OrigDocDate.Value; request.TaxOverride.TaxOverrideType = PX.TaxProvider.TaxOverrideType.TaxDate; mult = -1; } request.DocType = TaxDocumentType.ReturnInvoice; break; default: throw new PXException(Messages.DocTypeNotSupported); } PXSelectBase <APTran> select = new PXSelectJoin <APTran, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <APTran.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <APTran.accountID> > > >, Where <APTran.tranType, Equal <Current <APInvoice.docType> >, And <APTran.refNbr, Equal <Current <APInvoice.refNbr> >, And <APTran.lineType, NotEqual <SOLineType.discount> > > >, OrderBy <Asc <APTran.tranType, Asc <APTran.refNbr, Asc <APTran.lineNbr> > > > >(Base); request.Discount = GetDocDiscount().GetValueOrDefault(); foreach (PXResult <APTran, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { invoice })) { APTran tran = (APTran)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr.GetValueOrDefault(); line.Amount = mult * tran.CuryTranAmt.GetValueOrDefault(); line.Description = tran.TranDesc; line.OriginAddress = AddressConverter.ConvertTaxAddress(GetFromAddress(invoice, tran)); line.DestinationAddress = AddressConverter.ConvertTaxAddress(GetToAddress(invoice, tran)); line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.Qty.GetValueOrDefault()); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }
protected GetTaxRequest BuildGetTaxRequest(FSServiceOrder order) { if (order == null) { throw new PXArgumentException(ErrorMessages.ArgumentNullException); } BAccount cust = (BAccount)PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Select(Base, order.BillCustomerID); Location loc = (Location)PXSelect <Location, Where <Location.bAccountID, Equal <Required <Location.bAccountID> >, And <Location.locationID, Equal <Required <Location.locationID> > > > > . Select(Base, order.BillCustomerID, order.BillLocationID); IAddressBase addressFrom = GetFromAddress(); IAddressBase addressTo = GetToAddress(order); if (addressFrom == null) { throw new PXException(PX.Objects.CR.Messages.FailedGetFromAddressSO); } if (addressTo == null) { throw new PXException(PX.Objects.CR.Messages.FailedGetToAddressSO); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(order.TaxZoneID, Base.Accessinfo.BranchID); request.CurrencyCode = order.CuryID; request.CustomerCode = cust.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(addressFrom); request.DestinationAddress = AddressConverter.ConvertTaxAddress(addressTo); request.DocCode = $"CR.{order.SOID}"; request.DocDate = order.OrderDate.GetValueOrDefault(); int mult = 1; if (!string.IsNullOrEmpty(loc.CAvalaraCustomerUsageType)) { request.CustomerUsageType = loc.CAvalaraCustomerUsageType; } if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } request.DocType = TaxDocumentType.SalesOrder; PXSelectBase <FSSODet> select = new PXSelectJoin <FSSODet, LeftJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <FSSODet.inventoryID> >, LeftJoin <Account, On <Account.accountID, Equal <InventoryItem.salesAcctID> > > >, Where <FSSODet.sOID, Equal <Current <FSServiceOrder.sOID> > >, OrderBy <Asc <FSSODet.lineNbr> > >(Base); foreach (PXResult <FSSODet, InventoryItem, Account> res in select.View.SelectMultiBound(new object[] { order })) { FSSODet tran = (FSSODet)res; InventoryItem item = (InventoryItem)res; Account salesAccount = (Account)res; var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = mult * tran.CuryBillableTranAmt.GetValueOrDefault(); line.Description = tran.TranDesc; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = Math.Abs(tran.BillableQty.GetValueOrDefault()); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }
public virtual GetTaxRequest BuildGetTaxRequest(PMProforma doc) { if (doc == null) { throw new PXArgumentException(ErrorMessages.ArgumentNullException); } Customer cust = (Customer)Base.Customer.View.SelectSingleBound(new object[] { doc }); Location loc = (Location)Base.Location.View.SelectSingleBound(new object[] { doc }); IAddressBase fromAddress = GetFromAddress(doc); IAddressBase toAddress = GetToAddress(doc); if (fromAddress == null) { throw new PXException(Messages.FailedGetFromAddress); } if (toAddress == null) { throw new PXException(Messages.FailedGetToAddress); } GetTaxRequest request = new GetTaxRequest(); request.CompanyCode = CompanyCodeFromBranch(doc.TaxZoneID, doc.BranchID); request.CurrencyCode = doc.CuryID; request.CustomerCode = cust.AcctCD; request.OriginAddress = AddressConverter.ConvertTaxAddress(fromAddress); request.DestinationAddress = AddressConverter.ConvertTaxAddress(toAddress); request.DocCode = $"PM.{doc.RefNbr}"; request.DocDate = doc.InvoiceDate.GetValueOrDefault(); request.LocationCode = GetExternalTaxProviderLocationCode(doc); request.DocType = TaxDocumentType.SalesOrder; if (!string.IsNullOrEmpty(doc.AvalaraCustomerUsageType)) { request.CustomerUsageType = doc.AvalaraCustomerUsageType; } if (!string.IsNullOrEmpty(loc.CAvalaraExemptionNumber)) { request.ExemptionNo = loc.CAvalaraExemptionNumber; } foreach (PMProformaProgressLine tran in Base.ProgressiveLines.Select()) { InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <PMProformaProgressLine.inventoryID>(Base.ProgressiveLines.Cache, tran); Account salesAccount = (Account)PXSelectorAttribute.Select <PMProformaProgressLine.accountID>(Base.ProgressiveLines.Cache, tran); var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = tran.CuryLineTotal.GetValueOrDefault(); line.Description = tran.Description; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = tran.Qty.GetValueOrDefault(); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } foreach (PMProformaTransactLine tran in Base.TransactionLines.Select()) { InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <PMProformaTransactLine.inventoryID>(Base.TransactionLines.Cache, tran); Account salesAccount = (Account)PXSelectorAttribute.Select <PMProformaTransactLine.accountID>(Base.TransactionLines.Cache, tran); var line = new TaxCartItem(); line.Index = tran.LineNbr ?? 0; line.Amount = tran.CuryLineTotal.GetValueOrDefault(); line.Description = tran.Description; line.DestinationAddress = request.DestinationAddress; line.OriginAddress = request.OriginAddress; line.ItemCode = item.InventoryCD; line.Quantity = tran.Qty.GetValueOrDefault(); line.Discounted = request.Discount > 0; line.RevAcct = salesAccount.AccountCD; line.TaxCode = tran.TaxCategoryID; request.CartItems.Add(line); } return(request); }