Exemple #1
0
        public virtual IEnumerable ViewBook(PXAdapter adapter)
        {
            if (Trans.Current != null)
            {
                BookMaint graph = CreateInstance <BookMaint>();
                graph.Book.Current = PXSelect <FABook, Where <FABook.bookID, Equal <Current <FATran.bookID> > > > .Select(this);

                if (graph.Book.Current != null)
                {
                    throw new PXRedirectRequiredException(graph, true, "ViewBook")
                          {
                              Mode = PXBaseRedirectException.WindowMode.Same
                          };
                }
            }
            return(adapter.Get());
        }
Exemple #2
0
        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);
                }
            }
        }