protected override string GetMappedPeriodID(PXCache cache, OrganizationDependedPeriodKey newPeriodKey,
                                                    OrganizationDependedPeriodKey oldPeriodKey)
        {
            FinPeriod mappedFinPeriod = FinPeriodRepository.GetMappedPeriod(oldPeriodKey.OrganizationID, oldPeriodKey.PeriodID, newPeriodKey.OrganizationID);

            return(mappedFinPeriod?.FinPeriodID);
        }
        /// <summary>
        /// Check All Organizations & Set Error to FinPeriod Field
        /// </summary>
        private void ValidateRelatedToMainFinPeriods(PXCache cache, object oldRow, object newRow, bool externalCall,
                                                     int?newMainCalendarOrgID, int?oldMainCalendarOrgID, FinPeriod newMainOrgFinPeriod)
        {
            string oldMainOrgFinPeriodID = (string)cache.GetValue(oldRow, _FieldName);

            FinPeriod oldMainOrgFinPeriod = FinPeriodRepository.FindByID(oldMainCalendarOrgID, oldMainOrgFinPeriodID);

            if (newMainOrgFinPeriod.MasterFinPeriodID != oldMainOrgFinPeriod?.MasterFinPeriodID)
            {
                HashSet <int?> usedOrgIDs = new HashSet <int?>();

                if (IsHeader)
                {
                    usedOrgIDs.AddRange(CalendarOrganizationIDProvider.GetDetailOrganizationIDs(cache.Graph));
                }

                if (!usedOrgIDs.Any())
                {
                    return;
                }

                ProcessingResult existenceValidationResult =
                    FinPeriodRepository.FinPeriodsForMasterExist(newMainOrgFinPeriod.MasterFinPeriodID, usedOrgIDs.ToArray());

                if (!existenceValidationResult.IsSuccess)
                {
                    SetErrorAndResetForMainFields(cache, oldRow, newRow, oldMainCalendarOrgID, newMainCalendarOrgID,
                                                  externalCall,
                                                  new PXSetPropertyException(existenceValidationResult.GeneralMessage));
                }
            }
        }
Esempio n. 3
0
        public static FinPeriod FindNextPeriod(PXGraph graph, string fiscalPeriodId, bool aClosedOrActive)
        {
            FinPeriod nextperiod = null;

            if (!string.IsNullOrEmpty(fiscalPeriodId))
            {
                if (aClosedOrActive)
                {
                    nextperiod = PXSelect <FinPeriod,
                                           Where2 <
                                               Where <FinPeriod.closed, Equal <True>,
                                                      Or <FinPeriod.active, Equal <True> > >,
                                               And <FinPeriod.finPeriodID,
                                                    Greater <Required <FinPeriod.finPeriodID> > > >,
                                           OrderBy <Asc <FinPeriod.finPeriodID> >
                                           > .SelectWindowed(graph, 0, 1, fiscalPeriodId);
                }
                else
                {
                    nextperiod = PXSelect <FinPeriod,
                                           Where <FinPeriod.finPeriodID,
                                                  Less <Required <FinPeriod.finPeriodID> > >,
                                           OrderBy <Desc <FinPeriod.finPeriodID> >
                                           > .SelectWindowed(graph, 0, 1, fiscalPeriodId);
                }
            }
            if (nextperiod == null)
            {
                nextperiod = FindLastPeriod(graph, true);
            }
            return(nextperiod);
        }
        public virtual IEnumerable previousperiod(PXAdapter adapter)
        {
            GLHistoryEnqFilter filter     = Filter.Current as GLHistoryEnqFilter;
            FinPeriod          nextperiod = PXSelect <FinPeriod,
                                                      Where <FinPeriod.finPeriodID,
                                                             Less <Current <GLHistoryEnqFilter.finPeriodID> > >,
                                                      OrderBy <Desc <FinPeriod.finPeriodID> >
                                                      > .SelectWindowed(this, 0, 1);

            if (nextperiod == null)
            {
                nextperiod = PXSelectOrderBy <FinPeriod,
                                              OrderBy <Desc <FinPeriod.finPeriodID> >
                                              > .SelectWindowed(this, 0, 1);

                if (nextperiod == null)
                {
                    yield return(filter);
                }
            }

            filter.FinPeriodID = nextperiod != null ? nextperiod.FinPeriodID : null;

            yield return(filter);
        }
Esempio n. 5
0
        public virtual void GLAllocation_StartFinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            FinPeriod finPeriod = FinPeriodRepository.FindFinPeriodByDate(Accessinfo.BusinessDate, FinPeriod.organizationID.MasterValue);

            if (finPeriod != null)
            {
                e.NewValue = FinPeriodIDFormattingAttribute.FormatForDisplay(finPeriod.FinPeriodID);
            }
        }
Esempio n. 6
0
        public virtual void GLAllocation_StartFinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            PXSelectBase selectdate = new PXSelect <FinPeriod, Where <FinPeriod.startDate, LessEqual <Required <FinPeriod.startDate> >, And <FinPeriod.endDate, Greater <Required <FinPeriod.endDate> > > > >(this);
            FinPeriod    res        = selectdate.View.SelectSingle(Accessinfo.BusinessDate, Accessinfo.BusinessDate) as FinPeriod;

            if (res != null)
            {
                e.NewValue = FinPeriodIDFormattingAttribute.FormatForDisplay(res.FinPeriodID);
            }
        }
Esempio n. 7
0
        public virtual IEnumerable nextperiod(PXAdapter adapter)
        {
            GLHistoryEnqFilter filter = Filter.Current as GLHistoryEnqFilter;

            int?calendarOrganizationID = FinPeriodRepository.GetCalendarOrganizationID(filter.OrganizationID, filter.BranchID, filter.UseMasterCalendar);

            FinPeriod nextPeriod = FinPeriodRepository.FindNextPeriod(calendarOrganizationID, filter.FinPeriodID, looped: true);

            filter.FinPeriodID = nextPeriod != null ? nextPeriod.FinPeriodID : null;
            return(adapter.Get());
        }
        public virtual IEnumerable nextperiod(PXAdapter adapter)
        {
            GLHistoryEnqFilter filter     = CurrentFilter;
            FinPeriod          nextperiod = PXSelect <FinPeriod,
                                                      Where <FinPeriod.finPeriodID, Greater <Current <GLHistoryEnqFilter.finPeriodID> > >,
                                                      OrderBy <Asc <FinPeriod.finPeriodID> > > .SelectWindowed(this, 0, 1)
                                            ?? PXSelectOrderBy <FinPeriod,
                                                                OrderBy <Asc <FinPeriod.finPeriodID> > > .SelectWindowed(this, 0, 1);

            filter.FinPeriodID = nextperiod?.FinPeriodID;
            return(adapter.Get());
        }
Esempio n. 9
0
        public virtual void GLAllocation_EndFinPeriodID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            FinPeriod finPeriod = FinPeriodRepository.FindFinPeriodByDate(Accessinfo.BusinessDate, FinPeriod.organizationID.MasterValue);

            if (finPeriod != null)
            {
                FinPeriod lastPeriodOfYear = FinPeriodRepository.FindLastYearNotAdjustmentPeriod(finPeriod.FinYear, FinPeriod.organizationID.MasterValue);
                if (lastPeriodOfYear != null)
                {
                    e.NewValue = FinPeriodIDFormattingAttribute.FormatForDisplay(lastPeriodOfYear.FinPeriodID);
                }
            }
        }
Esempio n. 10
0
        public virtual void ClosePeriodProc(FinPeriod p)
        {
            FiscalPeriod_ID.Current = p;

            PostGraph pg = PXGraph.CreateInstance <PostGraph>();

            foreach (PXResult <Batch, BatchCopy> res in PXSelectJoin <Batch, LeftJoin <BatchCopy, On <BatchCopy.origModule, Equal <Batch.module>, And <BatchCopy.origBatchNbr, Equal <Batch.batchNbr>, And <BatchCopy.autoReverseCopy, Equal <True> > > > >, Where <Batch.finPeriodID, Equal <Required <Batch.finPeriodID> >, And <Batch.autoReverse, Equal <True>, And <Batch.released, Equal <True>, And <BatchCopy.origBatchNbr, IsNull> > > > > .Select(this, p.FinPeriodID))
            {
                pg.Clear();
                Batch copy = pg.ReverseBatchProc((Batch)res);
                pg.ReleaseBatchProc(copy);

                if (glsetup.Current.AutoPostOption == true)
                {
                    pg.PostBatchProc(copy);
                }
            }

            if (Unreleased != null || Unposted != null)
            {
                throw new PXException(Messages.PeriodHasUnpostedBatches);
            }

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                p.Closed     = true;
                p.DateLocked = true;
                p.APClosed   = true;
                p.ARClosed   = true;
                p.INClosed   = true;
                p.CAClosed   = true;
                p.FAClosed   = true;
                Caches[typeof(FinPeriod)].Update(p);

                if (Unclosed == null)
                {
                    if ((FinPeriod)NextFiscalYear.Select(p.FinYear) == null)
                    {
                        throw new PXException(Messages.NoPeriodsForNextYear);
                    }

                    CloseYearProc(p);
                }

                Caches[typeof(FinPeriod)].Persist(PXDBOperation.Update);
                Caches[typeof(FinPeriod)].Persisted(false);
                ts.Complete();
            }
        }
Esempio n. 11
0
        protected virtual void FinPeriod_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            FinPeriod per = (FinPeriod)e.Row;

            if (per == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <FinPeriod.active>(sender, per, false);

            FinPeriod p = PeriodList.Select();

            ShowDocuments.SetEnabled(p.Selected == true);
        }
Esempio n. 12
0
		protected override void ClosePeriodProc(FinPeriod p)
		{
			PXSelectBase select = new PXSelectJoin<ARRegister, 
											LeftJoin<ARAdjust, On<ARAdjust.adjgDocType, Equal<ARRegister.docType>, And<ARAdjust.adjgRefNbr, Equal<ARRegister.refNbr>, And<ARAdjust.released, Equal<False>>>>>,
											Where<ARRegister.voided, Equal<boolFalse>, 
											And<ARRegister.scheduled, Equal<boolFalse>,
											And<Where<ARAdjust.adjgFinPeriodID, IsNull, And<ARRegister.released, Equal<False>, And<ARRegister.finPeriodID, Equal<Required<ARRegister.finPeriodID>>, Or<ARAdjust.adjgFinPeriodID, Equal<Required<ARAdjust.adjgFinPeriodID>>>>>>>>>>(this);
			object doc = select.View.SelectSingle(p.FinPeriodID, p.FinPeriodID);
			if (doc != null)
			{			
				throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
			}			

			p.ARClosed = true;
			Caches[typeof(FinPeriod)].Update(p);
			Actions.PressSave();
		}
Esempio n. 13
0
		protected override void ClosePeriodProc(FinPeriod p)
		{
			PXSelectBase select = new PXSelect<CATran,
										  Where<CATran.finPeriodID, Equal<Required<CATran.finPeriodID>>,
											And<CATran.origModule, Equal<GL.BatchModule.moduleCA>,
											And<CATran.released, Equal<boolFalse>>>>>(this);
			CATran doc = (CATran)select.View.SelectSingle(p.FinPeriodID);
			if (doc != null)
			{
				throw new PXException(Messages.PeriodHasUnreleasedDocs);
			}

			p.CAClosed = true;
			Caches[typeof(FinPeriod)].Update(p);

			Actions.PressSave();
		}
        public virtual IEnumerable nextperiod(PXAdapter adapter)
        {
            GLHistoryEnqFilter filter     = Filter.Current as GLHistoryEnqFilter;
            FinPeriod          nextperiod = PXSelect <FinPeriod,
                                                      Where <FinPeriod.finPeriodID,
                                                             Greater <Current <GLHistoryEnqFilter.finPeriodID> > >,
                                                      OrderBy <Asc <FinPeriod.finPeriodID> >
                                                      > .SelectWindowed(this, 0, 1);

            if (nextperiod == null)
            {
                nextperiod = PXSelectOrderBy <FinPeriod,
                                              OrderBy <Asc <FinPeriod.finPeriodID> >
                                              > .SelectWindowed(this, 0, 1);
            }

            filter.FinPeriodID = nextperiod != null ? nextperiod.FinPeriodID : null;
            return(adapter.Get());
        }
        protected override void ValidatePeriodAndSourcesImpl(PXCache cache, object oldRow, object newRow,
                                                             bool externalCall)
        {
            int?newMainCalendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, newRow);
            int?oldMainCalendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, oldRow);

            if (HeaderMasterFinPeriodIDType != null && CalculatePeriodByHeader)
            {
                if (newMainCalendarOrgID != oldMainCalendarOrgID)
                {
                    string headerMasterPeriodID = GetHeaderMasterFinPeriodID(cache, newRow);

                    if (headerMasterPeriodID != null)
                    {
                        ProcessingResult <FinPeriod> procResult = FinPeriodRepository.GetFinPeriodByMasterPeriodID(newMainCalendarOrgID, headerMasterPeriodID);

                        if (!procResult.IsSuccess)
                        {
                            SetErrorAndResetToOldForField(
                                cache,
                                oldRow,
                                newRow,
                                CalendarOrganizationIDProvider.GetSourcesSpecification(cache, newRow).MainSpecificationItem.BranchSourceType.Name,
                                new PXSetPropertyException(procResult.GetGeneralMessage()),
                                externalCall);
                        }
                    }
                }
            }
            else
            {
                FinPeriod newMainOrgFinPeriod = GetAndValidateMainFinPeriod(cache, oldRow, newRow, externalCall);

                if (newMainOrgFinPeriod == null)
                {
                    return;
                }

                ValidateRelatedToMainFinPeriods(cache, oldRow, newRow, externalCall, newMainCalendarOrgID, oldMainCalendarOrgID, newMainOrgFinPeriod);

                ValidateNotMainRowLevelSources(cache, oldRow, newRow, externalCall, newMainOrgFinPeriod);
            }
        }
Esempio n. 16
0
		protected override void ClosePeriodProc(FinPeriod p)
		{
			PXSelectBase select = new PXSelect<INRegister,
										  Where<INRegister.finPeriodID, Equal<Required<INRegister.finPeriodID>>,
											And<INRegister.released, Equal<boolFalse>>>>(this);
			INRegister doc = (INRegister)select.View.SelectSingle(p.FinPeriodID);
			if (doc != null)
			{
				throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
			}

			//MS Landed cost will not be able to create these transactions if the period is closed
			LandedCostTran lcTranFromAP = PXSelectJoin<LandedCostTran,
										InnerJoin<APRegister, On<LandedCostTran.aPDocType, Equal<APRegister.docType>,
											And<LandedCostTran.aPRefNbr, Equal<APRegister.refNbr>>>>,
											Where<LandedCostTran.invoiceDate, GreaterEqual<Required<LandedCostTran.invoiceDate>>,
												And<LandedCostTran.invoiceDate, Less<Required<LandedCostTran.invoiceDate>>,
												And<LandedCostTran.source, Equal<LandedCostTranSource.fromAP>,
												And<APRegister.released, Equal<True>,
												And<LandedCostTran.processed, Equal<False>>>>>>>.Select(this, p.StartDate,p.EndDate);
			if (lcTranFromAP != null && lcTranFromAP.LCTranID.HasValue) 
			{
				throw new PXException(Messages.PeriodHasINDocsFromAP_LCToBeCreated);
			}

			PO.LandedCostTran lcTranFromPO = PXSelectJoin<LandedCostTran,
											InnerJoin<POReceipt, On<LandedCostTran.pOReceiptNbr, Equal<POReceipt.receiptNbr>>>,
											Where<LandedCostTran.invoiceDate, GreaterEqual<Required<LandedCostTran.invoiceDate>>,
												And<LandedCostTran.invoiceDate, Less<Required<LandedCostTran.invoiceDate>>,
											And<LandedCostTran.source, Equal<LandedCostTranSource.fromPO>,
											And<POReceipt.released, Equal<True>,											
											And<LandedCostTran.processed, Equal<False>>>>>>>.Select(this, p.StartDate, p.EndDate);
			if (lcTranFromPO != null && lcTranFromPO.LCTranID.HasValue)
			{
				throw new PXException(Messages.PeriodHasINDocsFromPO_LCToBeCreated);
			}

			p.INClosed = true;
			Caches[typeof(FinPeriod)].Update(p);

			Actions.PressSave();
		}
        protected virtual FinPeriod GetAndValidateMainFinPeriod(PXCache cache, object oldRow, object newRow, bool externalCall)
        {
            int?newMainCalendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, newRow);
            int?oldMainCalendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, oldRow);

            string    newMainOrgFinPeriodID = null;
            FinPeriod newMainOrgFinPeriod   = null;

            newMainOrgFinPeriodID = (string)cache.GetValue(newRow, _FieldName);

            if (newMainOrgFinPeriodID == null)
            {
                return(null);
            }

            newMainOrgFinPeriod = FinPeriodRepository.FindByID(newMainCalendarOrgID, newMainOrgFinPeriodID);

            if (newMainOrgFinPeriod == null)
            {
                string errorMessage = null;

                if (newMainCalendarOrgID == FinPeriod.organizationID.MasterValue)
                {
                    errorMessage = PXMessages.LocalizeFormatNoPrefix(Messages.MasterFinPeriodDoesNotExist,
                                                                     FormatForError(newMainOrgFinPeriodID));
                }
                else
                {
                    errorMessage = PXMessages.LocalizeFormatNoPrefix(
                        Messages.FinPeriodDoesNotExistForCompany,
                        FormatForError(newMainOrgFinPeriodID),
                        PXAccess.GetOrganizationCD(newMainCalendarOrgID));
                }

                SetErrorAndResetForMainFields(cache, oldRow, newRow, oldMainCalendarOrgID, newMainCalendarOrgID, externalCall,
                                              new PXSetPropertyException(errorMessage));

                return(null);
            }

            return(newMainOrgFinPeriod);
        }
Esempio n. 18
0
		protected override void ClosePeriodProc(FinPeriod p)
        {
            APRegister prebookedDoc = PXSelect<APRegister, Where<APRegister.voided, Equal<boolFalse>,
                                            And<APRegister.prebooked, Equal<boolTrue>,
                                            And<APRegister.released, Equal<boolFalse>,
                                            And<APRegister.finPeriodID, Equal<Required<APRegister.finPeriodID>>>>>>>.Select(this, p.FinPeriodID);
            if (prebookedDoc != null)
            {
                throw new PXException(Messages.PeriodHasPrebookedDocs);
            }

			PXSelectBase select = new PXSelectJoin<APRegister,
											LeftJoin<APAdjust, On<APAdjust.adjgDocType, Equal<APRegister.docType>, And<APAdjust.adjgRefNbr, Equal<APRegister.refNbr>, And<APAdjust.released, Equal<False>>>>>,
											Where<APRegister.voided, Equal<boolFalse>,
											And<APRegister.scheduled, Equal<boolFalse>,
											And<Where<APAdjust.adjgFinPeriodID, IsNull, And<APRegister.released, Equal<False>, And<APRegister.finPeriodID, Equal<Required<APRegister.finPeriodID>>, Or<APAdjust.adjgFinPeriodID, Equal<Required<APAdjust.adjgFinPeriodID>>>>>>>>>>(this); 
			object doc = select.View.SelectSingle(p.FinPeriodID, p.FinPeriodID);
			if (doc != null)
			{
				throw new PXException(Messages.PeriodHasUnreleasedDocs);
			}

			PO.LandedCostTran lcTran = PXSelectJoin<LandedCostTran,
											InnerJoin<POReceipt, On<LandedCostTran.pOReceiptNbr, Equal<POReceipt.receiptNbr>>>,
											Where<LandedCostTran.source, Equal<LandedCostTranSource.fromPO>,
											And<POReceipt.released, Equal<True>,
											And<LandedCostTran.postponeAP,Equal<False>,
											And<LandedCostTran.processed, Equal<False>,
												And<LandedCostTran.invoiceDate, GreaterEqual<Required<LandedCostTran.invoiceDate>>,				
												And<LandedCostTran.invoiceDate, Less<Required<LandedCostTran.invoiceDate>>>>>>>>>.Select(this, p.StartDate, p.EndDate);
			if (lcTran != null && lcTran.LCTranID.HasValue) 
			{
				throw new PXException(Messages.PeriodHasAPDocsFromPO_LCToBeCreated);
			}
			
			p.APClosed = true;
			Caches[typeof(FinPeriod)].Update(p);

			Actions.PressSave();
		}
        protected override void RedefaultPeriodID(PXCache cache, object row)
        {
            if (HeaderMasterFinPeriodIDType != null)
            {
                if (CalculatePeriodByHeader)
                {
                    string newFinPeriodID = null;

                    int?calendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, row);

                    if (calendarOrgID != null)
                    {
                        FinPeriod orgFinPeriod =
                            FinPeriodRepository.GetFinPeriodByMasterPeriodID(
                                calendarOrgID,
                                GetHeaderMasterFinPeriodID(cache, row))
                            .Result;

                        if (orgFinPeriod != null)
                        {
                            newFinPeriodID = FormatForDisplay(orgFinPeriod.FinPeriodID);
                        }
                    }

                    cache.SetValueExt(row, _FieldName, newFinPeriodID);
                }
            }
            else
            {
                base.RedefaultPeriodID(cache, row);

                if (AutoCalculateMasterPeriod)
                {
                    SetMasterPeriodID(cache, row);
                }
            }
        }
Esempio n. 20
0
        protected override void ClosePeriodProc(FinPeriod p)
        {
            PXSelectBase select = new PXSelect<FARegister,
                                          Where<FARegister.finPeriodID, Equal<Required<FARegister.finPeriodID>>,
                                            And<FARegister.released, Equal<False>>>>(this);
            FARegister doc = (FARegister)select.View.SelectSingle(p.FinPeriodID);
            if (doc != null)
            {
                throw new PXException(AP.Messages.PeriodHasUnreleasedDocs);
            }

            PXResult<FABookBalance, FixedAsset, FABook> res = (PXResult<FABookBalance, FixedAsset, FABook>)PXSelectJoin<FABookBalance, 
                                                                                                                        LeftJoin<FixedAsset, On<FixedAsset.assetID, Equal<FABookBalance.assetID>>, 
                                                                                                                        LeftJoin<FABook, On<FABookBalance.bookID, Equal<FABook.bookID>>, 
                                                                                                                        LeftJoin<FADetails, On<FADetails.assetID, Equal<FABookBalance.assetID>>>>>,
                                                                                                                        Where<FABookBalance.deprFromPeriod, LessEqual<Current<FinPeriod.finPeriodID>>, 
                                                                                                                            And<FABookBalance.deprToPeriod, GreaterEqual<Current<FinPeriod.finPeriodID>>, 
                                                                                                                            And<FABookBalance.updateGL, Equal<True>, 
                                                                                                                            And<FABookBalance.depreciate, Equal<True>,
                                                                                                                            And<FixedAsset.suspended, NotEqual<True>, 
                                                                                                                            And<FADetails.hold, NotEqual<True>, 
                                                                                                                            And<FABookBalance.initPeriod, IsNotNull,
                                                                                                                            And<Where<FABookBalance.currDeprPeriod, IsNull, 
                                                                                                                                    And<FABookBalance.status, Equal<FixedAssetStatus.active>,
                                                                                                                                    Or<FABookBalance.currDeprPeriod, LessEqual<Current<FinPeriod.finPeriodID>>>>>>>>>>>>>>.SelectSingleBound(this, new object[]{p});
            if(res != null)
            {
                FixedAsset asset = res;
                FABook book = res;
                throw new PXException(Messages.AssetNotDepreciatedInPeriod, asset.AssetCD, book.BookCode, FinPeriodIDAttribute.FormatForError(p.FinPeriodID));
            }

            p.FAClosed = true;
            Caches[typeof(FinPeriod)].Update(p);

            Actions.PressSave();
        }
        protected virtual IEnumerable AccountByPeriod(PXAdapter adapter)
        {
            if (this.EnqResult.Current != null)
            {
                AccountHistoryByYearEnq graph  = PXGraph.CreateInstance <AccountHistoryByYearEnq>();
                AccountByYearFilter     filter = PXCache <AccountByYearFilter> .CreateCopy(graph.Filter.Current);

                filter.AccountID   = this.EnqResult.Current.AccountID;
                filter.BranchID    = this.Filter.Current.BranchID;
                filter.LedgerID    = this.Filter.Current.LedgerID;
                filter.SubCD       = this.Filter.Current.SubCD;
                filter.FinPeriodID = this.EnqResult.Current.LastActivityPeriod;
                FinPeriod fp = PXSelect <FinPeriod, Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > > .Select(this, filter.FinPeriodID);

                if (fp != null)
                {
                    filter.FinYear = fp.FinYear;
                }
                filter.ShowCuryDetail = this.Filter.Current.ShowCuryDetail;
                graph.Filter.Update(filter);
                throw new PXRedirectRequiredException(graph, "Account By Period");
            }
            return(adapter.Get());
        }
Esempio n. 22
0
        public void CloseYearProc(FinPeriod p)
        {
            FinPeriod pnext = (FinPeriod)NextFiscalYear.Select(p.FinYear);

            foreach (AcctHist h in AcctHist_Close.Select())
            {
                AcctHist ins = new AcctHist();
                ins.FinPeriodID = pnext.FinPeriodID;
                ins.LedgerID    = h.LedgerID;
                ins.BranchID    = h.BranchID;
                ins.SubID       = h.SubID;
                ins.BalanceType = h.BalanceType;
                ins.CuryID      = h.CuryID;
                if (Object.Equals(h.AccountID, glsetup.Current.YtdNetIncAccountID))
                {
                    ins.AccountID = glsetup.Current.RetEarnAccountID;
                    Caches[typeof(AcctHist)].Insert(ins);
                }
                ins.AccountID = h.AccountID;
                Caches[typeof(AcctHist)].Insert(ins);
            }
            Caches[typeof(AcctHist)].Persist(PXDBOperation.Insert);
            Caches[typeof(AcctHist)].Persisted(false);
        }
        public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            SetUseMasterCalendarValue(sender, e.Row);

            if (HeaderMasterFinPeriodIDType != null && CalculatePeriodByHeader)
            {
                int?calendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(sender.Graph, sender, e.Row);

                FinPeriod orgFinPeriod =
                    FinPeriodRepository.GetFinPeriodByMasterPeriodID(
                        calendarOrgID,
                        GetHeaderMasterFinPeriodID(sender, e.Row))
                    .Result;

                if (orgFinPeriod != null)
                {
                    e.NewValue = FormatForDisplay(orgFinPeriod.FinPeriodID);
                }
            }
            else
            {
                base.FieldDefaulting(sender, e);
            }
        }
        public virtual string CalcMasterPeriodID(PXCache cache, object row)
        {
            string finPeriodID;

            finPeriodID = (string)cache.GetValue(row, _FieldName);

            int?calendarOrgID = CalendarOrganizationIDProvider.GetCalendarOrganizationID(cache.Graph, cache, row);

            if (calendarOrgID == FinPeriod.organizationID.MasterValue)
            {
                return(finPeriodID);
            }

            string masterFinPeriodID = null;

            if (finPeriodID != null)
            {
                FinPeriod orgFinPeriod = FinPeriodRepository.FindByID(calendarOrgID, finPeriodID);

                masterFinPeriodID = orgFinPeriod?.MasterFinPeriodID;
            }

            return(masterFinPeriodID);
        }
        /// <summary>
        /// TODO: Share function in <see cref="OrganizationMaint.CreateOrganizationCalendar"/> function
        /// </summary>
        /// <param name="organizationID"></param>
        /// <param name="masterFinPeriod"></param>
        /// <returns></returns>
        protected virtual OrganizationFinPeriod CopyOrganizationFinPeriodFromMaster(
            int organizationID,
            MasterFinPeriod masterFinPeriod,
            FinPeriod orgFinPeriodStatusSource,
            string yearNumber   = null,
            string periodNumber = null)
        {
            bool   isCentralizedManagement = PXAccess.FeatureInstalled <FeaturesSet.centralizedPeriodsManagement>();
            string organizationFinPeriodID = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber) ?? masterFinPeriod.FinPeriodID;

            OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod
            {
                OrganizationID    = organizationID,
                FinPeriodID       = organizationFinPeriodID,
                MasterFinPeriodID = masterFinPeriod.FinPeriodID,
                FinYear           = yearNumber ?? masterFinPeriod.FinYear,
                PeriodNbr         = periodNumber ?? masterFinPeriod.PeriodNbr,
                Custom            = masterFinPeriod.Custom,
                DateLocked        = masterFinPeriod.DateLocked,
                StartDate         = masterFinPeriod.StartDate,
                EndDate           = masterFinPeriod.EndDate,

                Status   = isCentralizedManagement ? masterFinPeriod.Status : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.Status : FinPeriod.status.Inactive,
                ARClosed = isCentralizedManagement ? masterFinPeriod.ARClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.ARClosed : false,
                APClosed = isCentralizedManagement ? masterFinPeriod.APClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.APClosed : false,
                FAClosed = isCentralizedManagement ? masterFinPeriod.FAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.FAClosed : false,
                CAClosed = isCentralizedManagement ? masterFinPeriod.CAClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.CAClosed : false,
                INClosed = isCentralizedManagement ? masterFinPeriod.INClosed : orgFinPeriodStatusSource != null ? orgFinPeriodStatusSource.INClosed : false,

                Descr = masterFinPeriod.Descr,
            };

            PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod);

            return(orgFinPeriod);
        }
Esempio n. 26
0
        public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate)
        {
            string lastBatchNbr = "0000000000";
            long   lastInfoID   = -1;

            IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate);

            using (PXTransactionScope ts = new PXTransactionScope())
            {
                foreach (ScheduleDet occurrence in occurrences)
                {
                    foreach (BatchNew scheduledBatch in PXSelect <
                                 BatchNew,
                                 Where <
                                     BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >,
                                     And <BatchNew.scheduled, Equal <boolTrue> > > >
                             .Select(this, schedule.ScheduleID))
                    {
                        BatchNew copy = PXCache <BatchNew> .CreateCopy(scheduledBatch);

                        copy.OrigBatchNbr = copy.BatchNbr;
                        copy.OrigModule   = copy.Module;
                        copy.CuryInfoID   = null;
                        copy.NumberCode   = "GLREC";
                        copy.NoteID       = null;

                        CurrencyInfo info = (CurrencyInfo)PXSelect <
                            CurrencyInfo,
                            Where <CurrencyInfo.curyInfoID, Equal <Required <CurrencyInfo.curyInfoID> > > >
                                            .Select(this, scheduledBatch.CuryInfoID);

                        if (info != null)
                        {
                            CurrencyInfo infocopy = PXCache <CurrencyInfo> .CreateCopy(info);

                            infocopy.CuryInfoID = lastInfoID;
                            copy.CuryInfoID     = lastInfoID;

                            CuryInfo_Created.Cache.Insert(infocopy);
                        }

                        copy.Posted          = false;
                        copy.Released        = false;
                        copy.Status          = BatchStatus.Balanced;
                        copy.Scheduled       = false;
                        copy.AutoReverseCopy = false;

                        copy.DateEntered = occurrence.ScheduledDate;

                        FinPeriod finPeriod =
                            FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(copy.BranchID), occurrence.ScheduledPeriod)
                            .GetValueOrRaiseError();
                        copy.FinPeriodID  = finPeriod.FinPeriodID;
                        copy.TranPeriodID = null;

                        copy.BatchNbr    = lastBatchNbr;
                        copy.RefBatchNbr = lastBatchNbr;

                        lastBatchNbr = AutoNumberAttribute.NextNumber(lastBatchNbr);
                        lastInfoID--;

                        copy = (BatchNew)Batch_Created.Cache.Insert(copy);

                        CurrencyInfoAttribute.SetEffectiveDate <Batch.dateEntered>(Batch_Created.Cache, new PXFieldUpdatedEventArgs(copy, null, false));
                        PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(BatchNew)], scheduledBatch, Batch_Created.Cache, copy);

                        foreach (GLTranNew scheduledBatchTransaction in PXSelect <
                                     GLTranNew,
                                     Where <
                                         GLTranNew.module, Equal <Required <GLTranNew.module> >,
                                         And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > >
                                 .Select(this, scheduledBatch.Module, scheduledBatch.BatchNbr))
                        {
                            GLTranNew transactionCopy = PXCache <GLTranNew> .CreateCopy(scheduledBatchTransaction);

                            transactionCopy.OrigBatchNbr = transactionCopy.BatchNbr;
                            transactionCopy.OrigModule   = transactionCopy.Module;
                            transactionCopy.BatchNbr     = copy.BatchNbr;
                            transactionCopy.RefBatchNbr  = copy.RefBatchNbr;
                            transactionCopy.CuryInfoID   = copy.CuryInfoID;
                            transactionCopy.CATranID     = null;
                            transactionCopy.NoteID       = null;

                            transactionCopy.TranDate = occurrence.ScheduledDate;
                            FinPeriodIDAttribute.SetPeriodsByMaster <GLTranNew.finPeriodID>(Tran_Created.Cache, transactionCopy, occurrence.ScheduledPeriod);

                            transactionCopy = Tran_Created.Cache.Insert(transactionCopy) as GLTranNew;
                            PXNoteAttribute.CopyNoteAndFiles(Tran_Created.Cache, scheduledBatchTransaction, Tran_Created.Cache, transactionCopy);
                        }
                    }

                    schedule.LastRunDate = occurrence.ScheduledDate;
                    Running_Schedule.Cache.Update(schedule);
                }

                Running_Schedule.Cache.Persist(PXDBOperation.Update);

                Batch_Created.Cache.Persist(PXDBOperation.Insert);
                Batch_Created.Cache.Persist(PXDBOperation.Update);

                foreach (GLTranNew createdTransaction in Tran_Created.Cache.Inserted)
                {
                    foreach (BatchNew createdBatch in Batch_Created.Cache.Cached)
                    {
                        if (object.Equals(createdBatch.RefBatchNbr, createdTransaction.RefBatchNbr))
                        {
                            createdTransaction.BatchNbr   = createdBatch.BatchNbr;
                            createdTransaction.CuryInfoID = createdBatch.CuryInfoID;

                            if (!string.IsNullOrEmpty(createdBatch.RefNbr))
                            {
                                createdTransaction.RefNbr = createdBatch.RefNbr;
                            }

                            break;
                        }
                    }
                }

                Tran_Created.Cache.Normalize();

                Tran_Created.Cache.Persist(PXDBOperation.Insert);
                Tran_Created.Cache.Persist(PXDBOperation.Update);
                Caches[typeof(CA.CADailySummary)].Persist(PXDBOperation.Insert);

                ts.Complete(this);
            }

            Running_Schedule.Cache.Persisted(false);
            Batch_Created.Cache.Persisted(false);
            Tran_Created.Cache.Persisted(false);
            Caches[typeof(CA.CADailySummary)].Persisted(false);
        }
        private void ValidateNotMainRowLevelSources(PXCache cache, object oldRow, object newRow, bool externalCall, FinPeriod newMainOrgFinPeriod)
        {
            ValidationResult validationResult = ValidateRowLevelSources(
                CalendarOrganizationIDProvider,
                cache,
                newRow,
                organizationID => FinPeriodRepository
                .GetFinPeriodByMasterPeriodID(organizationID, newMainOrgFinPeriod.MasterFinPeriodID).IsSuccess,
                skipMain: true);

            if (validationResult.HasErrors)
            {
                foreach (var branchValue in validationResult.BranchValuesWithErrors)
                {
                    if (branchValue.SpecificationItem.BranchSourceType != null &&
                        (branchValue.SpecificationItem.BranchSourceFormulaType != null ||
                         PXAccess.FeatureInstalled <FeaturesSet.branch>()))
                    {
                        PXCache branchCache = cache.Graph.Caches[BqlCommand.GetItemType(branchValue.SpecificationItem.BranchSourceType)];
                        object  newBranch   = branchCache.GetItemType().IsAssignableFrom(newRow.GetType())
                                                        ? newRow
                                                        : branchCache.Current;
                        object oldBranch = branchCache.GetItemType().IsAssignableFrom(oldRow.GetType())
                                                        ? oldRow
                                                        : branchCache.Current;

                        string organizationCD =
                            PXAccess.GetOrganizationCD(
                                PXAccess.GetParentOrganizationID(branchValue.SourceBranchIDs.Single()));

                        var exception = new PXSetPropertyException(
                            Messages.RelatedFinPeriodForMasterDoesNotExistForCompany,
                            FormatForError(newMainOrgFinPeriod.MasterFinPeriodID),
                            organizationCD);

                        SetErrorAndResetToOldForField(
                            branchCache,
                            oldBranch,
                            newBranch,
                            branchValue.SpecificationItem.BranchSourceType.Name,
                            exception,
                            externalCall);
                    }
                }
            }
        }
Esempio n. 28
0
        public void CreateBatch(JournalEntry je, string periodId, int?ledgerID, int?branchID, GLConsolSetup item)
        {
            je.Clear();

            je.glsetup.Current.RequireControlTotal = false;

            Ledger ledger = PXSelect <Ledger,
                                      Where <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > >
                            .Select(this, ledgerID);

            FinPeriod fiscalPeriod = PXSelect <FinPeriod,
                                               Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > > .
                                     Select(this, periodId);

            if (fiscalPeriod == null)
            {
                throw new FiscalPeriodInvalidException(periodId);
            }

            je.Accessinfo.BusinessDate = fiscalPeriod.EndDate.Value.AddDays(-1);

            CurrencyInfo info = new CurrencyInfo();

            info.CuryID      = ledger.BaseCuryID;
            info.CuryEffDate = fiscalPeriod.EndDate.Value.AddDays(-1);
            info.CuryRate    = (decimal)1.0;
            info             = je.currencyinfo.Insert(info);

            Batch batch = new Batch();

            batch.TranPeriodID = periodId;
            batch.BranchID     = branchID;
            batch.LedgerID     = ledgerID;
            batch.Module       = BatchModule.GL;
            batch.Hold         = false;
            batch.Released     = false;
            batch.CuryID       = ledger.BaseCuryID;
            batch.CuryInfoID   = info.CuryInfoID;
            batch.FinPeriodID  = periodId;
            batch.CuryID       = ledger.BaseCuryID;
            batch.BatchType    = BatchTypeCode.Consolidation;
            batch.Description  = PXMessages.LocalizeFormatNoPrefix(Messages.ConsolidationBatch, item.Description);
            batch = je.BatchModule.Insert(batch);

            foreach (GLConsolRead read in listConsolRead)
            {
                Action <decimal?, decimal?> insertTransaction = (debitAmt, creditAmt) =>
                {
                    GLTran tran = new GLTran();

                    tran.AccountID     = read.AccountID;
                    tran.SubID         = read.SubID;
                    tran.CuryInfoID    = info.CuryInfoID;
                    tran.CuryCreditAmt = creditAmt;
                    tran.CuryDebitAmt  = debitAmt;
                    tran.CreditAmt     = creditAmt;
                    tran.DebitAmt      = debitAmt;
                    tran.TranType      = GLTran.tranType.Consolidation;
                    tran.TranClass     = GLTran.tranClass.Consolidation;
                    tran.TranDate      = fiscalPeriod.EndDate.Value.AddDays(-1);
                    tran.TranDesc      = Messages.ConsolidationDetail;
                    tran.TranPeriodID  = periodId;
                    tran.RefNbr        = "";
                    tran.ProjectID     = PM.ProjectDefaultAttribute.NonProject();
                    tran = je.GLTranModuleBatNbr.Insert(tran);

                    if (tran != null && tran.SubID == null && read.MappedValue != null)
                    {
                        je.GLTranModuleBatNbr.SetValueExt <GLTran.subID>(tran, read.MappedValue);
                    }

                    if (tran == null || tran.AccountID == null || tran.SubID == null)
                    {
                        throw new PXException(Messages.AccountOrSubNotFound, read.AccountCD, read.MappedValue);
                    }
                };

                if (Math.Abs((decimal)read.ConsolAmtDebit) > 0)
                {
                    insertTransaction(read.ConsolAmtDebit, 0m);
                }

                if (Math.Abs((decimal)read.ConsolAmtCredit) > 0)
                {
                    insertTransaction(0m, read.ConsolAmtCredit);
                }
            }

            item.LastPostPeriod = periodId;
            item.LastConsDate   = DateTime.Now;
            je.Caches[typeof(GLConsolSetup)].Update(item);
            if (!je.Views.Caches.Contains(typeof(GLConsolSetup)))
            {
                je.Views.Caches.Add(typeof(GLConsolSetup));
            }
            GLConsolBatch cb = new GLConsolBatch();

            cb.SetupID = item.SetupID;
            je.Caches[typeof(GLConsolBatch)].Insert(cb);
            if (!je.Views.Caches.Contains(typeof(GLConsolBatch)))
            {
                je.Views.Caches.Add(typeof(GLConsolBatch));
            }

            try
            {
                je.Save.Press();
            }
            catch (PXException e)
            {
                try
                {
                    if (!String.IsNullOrEmpty(PXUIFieldAttribute.GetError <Batch.curyCreditTotal>(je.BatchModule.Cache, je.BatchModule.Current)) ||
                        !String.IsNullOrEmpty(PXUIFieldAttribute.GetError <Batch.curyDebitTotal>(je.BatchModule.Cache, je.BatchModule.Current)))
                    {
                        je.BatchModule.Current.Hold = true;
                        je.BatchModule.Update(je.BatchModule.Current);
                    }
                    je.Save.Press();
                    if (exception == null)
                    {
                        exception = new PXException(Messages.ConsolidationBatchOutOfBalance, je.BatchModule.Current.BatchNbr);
                    }
                    else
                    {
                        exception = new PXException(exception.Message + Messages.ConsolidationBatchOutOfBalance, je.BatchModule.Current.BatchNbr);
                    }
                }
                catch
                {
                    throw e;
                }
            }
        }
        protected virtual OrganizationFinYear GenerateSingleOrganizationFinYear(int organizationID, MasterFinYear startMasterYear, MasterFinPeriod startMasterFinPeriod)
        {
            if (startMasterYear == null)
            {
                throw new ArgumentNullException(nameof(startMasterYear));
            }
            if (startMasterFinPeriod == null)
            {
                throw new ArgumentNullException(nameof(startMasterFinPeriod));
            }

            OrganizationFinYear newOrganizationFinYear = (OrganizationFinYear)this.Caches <OrganizationFinYear>().Insert(
                new OrganizationFinYear
            {
                OrganizationID         = organizationID,
                Year                   = startMasterYear.Year,
                FinPeriods             = startMasterYear.FinPeriods,
                StartMasterFinPeriodID = startMasterFinPeriod.FinPeriodID,
                StartDate              = startMasterFinPeriod.StartDate,
            });

            short           periodNumber          = 1;
            MasterFinPeriod sourceMasterFinPeriod = startMasterFinPeriod;
            int             periodsCountForCopy   = (int)newOrganizationFinYear.FinPeriods;

            if (YearSetup.Current.HasAdjustmentPeriod == true)
            {
                periodsCountForCopy--;
            }
            OrganizationFinPeriod newOrganizationFinPeriod = null;

            FinPeriod firstOrgFinPeriod = FinPeriodRepository.FindFirstPeriod(organizationID, clearQueryCache: true);

            while (periodNumber <= periodsCountForCopy)
            {
                newOrganizationFinPeriod = (OrganizationFinPeriod)this.Caches <OrganizationFinPeriod>().Insert(
                    CopyOrganizationFinPeriodFromMaster(
                        organizationID,
                        sourceMasterFinPeriod,
                        firstOrgFinPeriod != null && Convert.ToInt32(firstOrgFinPeriod.FinYear) > Convert.ToInt32(newOrganizationFinYear.Year) ? firstOrgFinPeriod : null,
                        newOrganizationFinYear.Year,
                        $"{periodNumber:00}"));

                if (periodNumber < periodsCountForCopy)                 // no need to search for the next master period if last organization period is generated
                {
                    string sourceMasterFinPeriodID = sourceMasterFinPeriod.FinPeriodID;
                    while ((sourceMasterFinPeriod = FinPeriodRepository.FindNextNonAdjustmentMasterFinPeriod(sourceMasterFinPeriodID, clearQueryCache: true)) == null)
                    {
                        MasterCalendarGraph.Clear();
                        MasterCalendarGraph.GenerateNextMasterFinYear();
                    }
                }

                periodNumber++;
            }
            newOrganizationFinYear.EndDate = newOrganizationFinPeriod.EndDate;
            if (YearSetup.Current.HasAdjustmentPeriod == true)
            {
                this.Caches <OrganizationFinPeriod>().Insert(GenerateAdjustmentOrganizationFinPeriod(organizationID, newOrganizationFinPeriod));
            }

            return(newOrganizationFinYear);
        }
Esempio n. 30
0
 protected virtual void ClosePeriodProc(FinPeriod p)
 {
 }