protected override string GetMappedPeriodID(PXCache cache, OrganizationDependedPeriodKey newPeriodKey, OrganizationDependedPeriodKey oldPeriodKey) { IFABookPeriodRepository periodRepository = cache.Graph.GetService <IFABookPeriodRepository>(); FABookPeriod mappedPeriod = periodRepository.FindMappedPeriod((FABookPeriod.Key)oldPeriodKey, (FABookPeriod.Key)newPeriodKey); return(mappedPeriod?.FinPeriodID); }
public virtual OrganizationFinPeriod GetNearestOpenOrganizationMappedFABookPeriodInSubledger <TClosedInSubledgerField>(int?bookID, int?sourceBranchID, string sourcefinPeriodID, int?targetBranchID) where TClosedInSubledgerField : IBqlField { if (!FABookPeriodRepositoryHelper.IsPostingFABook(bookID)) { return(null); } IFinPeriodUtils finPeriodUtils = Graph.GetService <IFinPeriodUtils>(); IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>(); IFABookPeriodRepository faBookPeriodRepository = Graph.GetService <IFABookPeriodRepository>(); int?sourceOrganizationID = PXAccess.GetParentOrganizationID(sourceBranchID); int?targetOrganizationID = PXAccess.GetParentOrganizationID(targetBranchID); // Mapped book period - first way: // FABookPeriod of sourceBranchID -> master book Period -> FABookPeriod of targetBranchID // ProcessingResult <FABookPeriod> targetFABookPeriod = faBookPeriodRepository.FindMappedFABookPeriod( bookID, sourceOrganizationID, sourcefinPeriodID, targetOrganizationID); // Mapped book period - second way: // finPeriodID of sourceBranchID -> masterFinPeriod -> FinPeriodID of targetBranchID -> FABookPeriod of targetBranchID // if (targetFABookPeriod.Result == null) { ProcessingResult <FABookPeriod> targetFABookPeriodSecondWay = faBookPeriodRepository.FindMappedFABookPeriodUsingFinPeriod( bookID, sourceOrganizationID, sourcefinPeriodID, targetOrganizationID); targetFABookPeriodSecondWay.RaiseIfHasError(); targetFABookPeriod = targetFABookPeriodSecondWay; } OrganizationFinPeriod period = finPeriodUtils.GetNearestOpenOrganizationFinPeriodInSubledger <TClosedInSubledgerField>(targetFABookPeriod.ThisOrRaiseIfHasError().Result); return(period); }
protected override void ValidatePeriodAndSourcesImpl(PXCache cache, object oldRow, object newRow, bool externalCall) { PeriodKeyProviderBase.KeyWithSourceValuesCollection < FABookPeriodKeyProvider.FAKeyWithSourceValues, FABookPeriodKeyProvider.FASourceSpecificationItem, FABookPeriod.Key> newKeyWithSourceValues = FABookPeriodKeyProvider.GetKeys(cache.Graph, cache, newRow); PeriodKeyProviderBase.KeyWithSourceValuesCollection < FABookPeriodKeyProvider.FAKeyWithSourceValues, FABookPeriodKeyProvider.FASourceSpecificationItem, FABookPeriod.Key> oldKeyWithSourceValues = FABookPeriodKeyProvider.GetKeys(cache.Graph, cache, oldRow); FABookPeriod.Key newPeriodKey = newKeyWithSourceValues.ConsolidatedKey; newPeriodKey.PeriodID = (string)cache.GetValue(newRow, _FieldName); if (!newPeriodKey.Defined) { return; } IFABookPeriodRepository periodRepository = cache.Graph.GetService <IFABookPeriodRepository>(); FABookPeriod period = periodRepository.FindByKey(newPeriodKey.BookID, newPeriodKey.OrganizationID, newPeriodKey.PeriodID); if (period == null) { PXSetPropertyException exception = null; FABook book = BookMaint.FindByID(cache.Graph, newPeriodKey.BookID); if (book.UpdateGL == true) { exception = new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix( Messages.PeriodDoesNotExistForBookAndCompany, FormatForError(newPeriodKey.PeriodID), book.BookCode, PXAccess.GetOrganizationCD(newPeriodKey.OrganizationID))); if (FAMainSpecificationItem.OrganizationSourceType != null && newKeyWithSourceValues.MainItem.SourceOrganizationIDs.First() != null && newKeyWithSourceValues.MainItem.SourceOrganizationIDs.First() != oldKeyWithSourceValues.MainItem.SourceOrganizationIDs.First()) { SetErrorAndResetToOldForField( cache, oldRow, newRow, FAMainSpecificationItem.OrganizationSourceType.Name, exception, externalCall); } if (FAMainSpecificationItem.BranchSourceType != null && newKeyWithSourceValues.MainItem.SourceBranchIDs.First() != null && newKeyWithSourceValues.MainItem.SourceBranchIDs.First() != oldKeyWithSourceValues.MainItem.SourceBranchIDs.First()) { SetErrorAndResetToOldForField( cache, oldRow, newRow, FAMainSpecificationItem.BranchSourceType.Name, exception, externalCall); } if (FAMainSpecificationItem.AssetSourceType != null && newKeyWithSourceValues.MainItem.SourceAssetIDs.First() != null && newKeyWithSourceValues.MainItem.SourceAssetIDs.First() != oldKeyWithSourceValues.MainItem.SourceAssetIDs.First()) { SetErrorAndResetToOldForField( cache, oldRow, newRow, FAMainSpecificationItem.AssetSourceType.Name, exception, externalCall); } } else { exception = new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix( Messages.PeriodDoesNotExistForBook, FormatForError(newPeriodKey.PeriodID))); } cache.RaiseExceptionHandling( _FieldName, newRow, FormatForDisplay(newPeriodKey.PeriodID), exception); cache.SetValue( newRow, _FieldName, cache.GetValue(oldRow, _FieldName)); if (FAMainSpecificationItem.BookSourceType != null && newKeyWithSourceValues.MainItem.SourceBookIDs.First() != null && newKeyWithSourceValues.MainItem.SourceBookIDs.First() != oldKeyWithSourceValues.MainItem.SourceBookIDs.First()) { SetErrorAndResetToOldForField( cache, oldRow, newRow, FAMainSpecificationItem.BookSourceType.Name, exception, externalCall); } } }
public FABookPeriodUtils(PXGraph graph) { Graph = graph; FABookPeriodRepositoryHelper = Graph.GetService <IFABookPeriodRepository>(); }