Skip to main content

 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]
        rCurrencyInfo]
        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
        gPXUIField(DisplayName = "Item Amount", Enabled = false, Visibility = PXUIVisibility.Visible)]
        =PXDBCurrency(typeof(curyInfoID), typeof(ItemAmt))]
        PPXDefault(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] 

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


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


@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


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
     pPXDBString(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)]
        mPXDBCurrency(typeof(curyInfoID), typeof(ItemAmt))]
        VPXDefault(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>

   


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


Reply