Solved

Adding Currency Conversion To Screen

  • 2 June 2023
  • 5 replies
  • 225 views

Userlevel 2
Badge

 I am trying to add currency conversion from base to selected currency but cant seem to put the pieces together. I am able to save the base currency but the conversions is not working. What am I missing?

 

The DAC

class GTItems 
{
         #region CuryInfoID
        [PXDBLong]
        [CurrencyInfo]
        public virtual long? CuryInfoID { get; set; }
        public abstract class curyInfoID : PX.Data.BQL.BqlLong.Field<curyInfoID> { }
        #endregion

        #region ItemAmt
        [PXDBBaseCury]
        [PXDefault(TypeCode.Decimal, "0.0")]
        public virtual Decimal? ItemAmt { get; set; }
        public abstract class ItemAmt : PX.Data.BQL.BqlDecimal.Field<ItemAmt> { }
        #endregion

        #region CuryItemAmt
        [PXUIField(DisplayName = "Item Amount", Enabled = false, Visibility = PXUIVisibility.Visible)]
        [PXDBCurrency(typeof(curyInfoID), typeof(ItemAmt))]
        [PXDefault(TypeCode.Decimal, "0.0")]
        public virtual Decimal? CuryItemAmt { get; set; }
        public abstract class curyItemAmt : PX.Data.BQL.BqlDecimal.Field<curyItemAmt> { }
        #endregion
}

 

The Graph
public class ItemsMaint : PXGraph<ItemsMaint, GTItems>
{
 public PXSelect<GTItems> Items;
 public PXSelect<CurrencyInfo, Where<CurrencyInfo.curyInfoID, Equal<Current<GTItems.curyInfoID>>>> currencyinfo;

}

 

 Added to ASPX Pages

Included this link in the aspx pages for FormView
<pxa:PXCurrencyRate DataField="Curyid" ID="edCury" runat="server" RateTypeView="currencyinfo" DataMember="_Currency_" />  
[I dont know where _Currency_ is from, got this from browsing through other acumatica screens] 

icon

Best answer by robert38 10 July 2023, 13:25

View original

5 replies

Badge +18

Hello @robert38 ,

[I dont know where _Currency_ is from, got this from browsing through other acumatica screens] 

I searched the Acumatica Community and found some information about where other people found the currency conversion data they needed for GI’s and reports.  Did you see these posts containing useful currency conversion tips?

 

If these posts don’t solve your question, it’s helpful if you can show us the result of your code:  do you see incorrect numbers?  Do you see an error?  (It’s hard to answer accurately based on “It’s not working”).  Thank you!😀

Userlevel 7
Badge +10

Hi @robert38 

To handle currency conversion, you will need to query the CurrencyRate table and perform currency calculations, such as multiplication and division, to convert between currencies.

Regards,

Sweta

Userlevel 2
Badge

@Laura02  This has to do with adding the currency conversion control to a custom screen and modified screen and not a GI. 

@sweta68 I thought acumatica handled that automatically with <pxa: component in aspx page

Userlevel 2
Badge

Thanks for the help 
I was able to figure the entire cycle. This may help someone 😉 . The currency pxa:Currency requires that you set the effective date and rate type (spot, etc) which is done use the event handlers in BLC and ToggleCurrency
 

The DAC

class GTItems 
{
         #region CuryInfoID
        [PXDBLong]
        [CurrencyInfo]
        public virtual long? CuryInfoID { get; set; }
        public abstract class curyInfoID : PX.Data.BQL.BqlLong.Field<curyInfoID> { }
        #endregion

 

     #region CuryId
     [PXDBString(5, IsUnicode = true, InputMask = ">LLLLL")]
     [PXUIField(DisplayName = "Currency", Enabled = false)]             
    [PXUIField(DisplayName = "Currency ID")]

        public virtual string CuryID { get; set; }
    #endregion

        #region ItemAmt
        [PXDBBaseCury]
        [PXDefault(TypeCode.Decimal, "0.0")]
        public virtual Decimal? ItemAmt { get; set; }
        public abstract class ItemAmt : PX.Data.BQL.BqlDecimal.Field<ItemAmt> { }
        #endregion

        #region CuryItemAmt
        [PXUIField(DisplayName = "Item Amount", Enabled = false, Visibility = PXUIVisibility.Visible)]
        [PXDBCurrency(typeof(curyInfoID), typeof(ItemAmt))]
        [PXDefault(TypeCode.Decimal, "0.0")]
        public virtual Decimal? CuryItemAmt { get; set; }
        public abstract class curyItemAmt : PX.Data.BQL.BqlDecimal.Field<curyItemAmt> { }
        #endregion
}

 

The graph contains  view of the currencyinfo, event handler and events for add effdate

The Graph
public class ItemsMaint : PXGraph<ItemsMaint, GTItems>
{
     public PXSelect<GTItems> Items;
     public PXSelect<CurrencyInfo, Where<CurrencyInfo.curyInfoID,  Equal<Current<GTItems.curyInfoID>>>> currencyinfo;

 

     public ToggleCurrency<GTItems> CurrencyView;


        #region CurrencyInfo Events


        protected virtual void _(Events.FieldDefaulting<CurrencyInfo, CurrencyInfo.curyID> e)
        {
            if (PXAccess.FeatureInstalled<FeaturesSet.multicurrency>())
            {
                if (Accessinfo.BaseCuryID != null )
                {
                    e.NewValue = Accessinfo.BaseCuryID;
                    e.Cancel = true;
            }
        }

        protected virtual void _(Events.FieldDefaulting<CurrencyInfo, CurrencyInfo.curyRateTypeID> e)
        {
            if (PXAccess.FeatureInstalled<FeaturesSet.multicurrency>())
            {     

              if( Accessinfo.CuryRateID != null)
                {
                       e.NewValue = Accessinfo.CuryRateID;
                       e.Cancel = true; 
                } else {
                     e.NewValue = "SPOT";
                      e.Cancel = true;  
             }

            }
        }

        protected virtual void _(Events.FieldDefaulting<CurrencyInfo, CurrencyInfo.curyEffDate> e)
        {
                e.NewValue = DateTime.UtcNow;
                e.Cancel = true;
            
        }

        protected virtual void _(Events.RowSelected<CurrencyInfo> e)
        {
            CurrencyInfo info = e.Row as CurrencyInfo;
            if (info != null)
            {
                bool curyenabled = info.AllowUpdate(this.Lines.Cache);

                PXUIFieldAttribute.SetEnabled<CurrencyInfo.curyRateTypeID>(e.Cache, info, curyenabled);
                PXUIFieldAttribute.SetEnabled<CurrencyInfo.curyEffDate>(e.Cache, info, curyenabled);
                PXUIFieldAttribute.SetEnabled<CurrencyInfo.sampleCuryRate>(e.Cache, info, curyenabled);
                PXUIFieldAttribute.SetEnabled<CurrencyInfo.sampleRecipRate>(e.Cache, info, curyenabled);
            }
        }
        #endregion

}

 

In the ASPX 

 

In a PXFormView 

<pxa:PXCurrencyRate DataField="CuryID" ID="edCury" runat="server" RateTypeView="currencyinfo"    DataMember="_Currency_"></pxa:PXCurrencyRate>

 

In PXDataSource 

<CallbackCommands>
            <px:PXDSCallbackCommand Visible="False" Name="CurrencyView" />
</CallbackCommands>

   

Userlevel 7
Badge

Thank you for sharing your solution with the community @robert38!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved