Skip to main content
Solved

Adding Currency Conversion To Screen


Forum|alt.badge.img

 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] 

Best answer by robert38

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>

   

View original
Did this topic help you find an answer to your question?

5 replies

Laura02
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3132 replies
  • June 3, 2023

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!😀


Forum|alt.badge.img+9
  • Semi-Pro III
  • 229 replies
  • June 6, 2023

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


Forum|alt.badge.img
  • Author
  • Freshman II
  • 13 replies
  • June 7, 2023

@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


Forum|alt.badge.img
  • Author
  • Freshman II
  • 13 replies
  • Answer
  • July 10, 2023

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>

   


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2754 replies
  • July 10, 2023

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings