protected virtual void DRDeferredCode_Method_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { DRDeferredCode row = e.Row as DRDeferredCode; if (row != null && row.Method == DeferredMethodType.CashReceipt) { row.AccountType = DeferredAccountType.Income; } if (DeferredMethodType.RequiresTerms(row)) { sender.SetValueExt <DRDeferredCode.accountType>(row, DeferredAccountType.Income); sender.SetDefaultExt <DRDeferredCode.startOffset>(row); sender.SetDefaultExt <DRDeferredCode.occurrences>(row); } else { sender.SetDefaultExt <DRDeferredCode.recognizeInPastPeriods>(row); } if (row.Method == DeferredMethodType.CashReceipt) { sender.SetValueExt <DRDeferredCode.accountType>(row, DeferredAccountType.Income); } }
/// <summary> /// Checks the presence and consistency of deferral term start / end dates, /// as well as ensures that the document date is no later than the Term End Date /// in case recognizing in past periods is forbidden. /// </summary> /// <param name="deferralSchedule"> /// Deferral schedule from which the document date will be taken. /// </param> protected virtual void ValidateTerms(DRSchedule deferralSchedule) { if (!DeferredMethodType.RequiresTerms(_code)) { return; } if (!deferralSchedule.TermStartDate.HasValue || !deferralSchedule.TermEndDate.HasValue) { throw new PXException(Messages.CannotGenerateTransactionsWithoutTerms); } if (deferralSchedule.TermStartDate > deferralSchedule.TermEndDate) { throw new PXException( Messages.TermCantBeNegative, deferralSchedule.TermEndDate, deferralSchedule.TermStartDate); } if (_code.RecognizeInPastPeriods != true && deferralSchedule.DocDate > deferralSchedule.TermEndDate) { throw new PXException(Messages.TermEndDateIsEarlierThanDocDate, _code.DeferredCodeID); } }
protected virtual void DRDeferredCode_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { DRDeferredCode deferralCode = e.Row as DRDeferredCode; if (!DeferredMethodType.RequiresTerms(deferralCode) && deferralCode.MultiDeliverableArrangement != true && deferralCode.Occurrences == 0) { sender.RaiseExceptionHandling <DRDeferredCode.occurrences>( e.Row, deferralCode.Occurrences, new PXSetPropertyException(Messages.NoZeroOccurrencesForRecognitionMethod)); } }
protected virtual void DRDeferredCode_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { DRDeferredCode deferralCode = e.Row as DRDeferredCode; PXDefaultAttribute.SetPersistingCheck <DRDeferredCode.accountID>(sender, deferralCode, deferralCode.MultiDeliverableArrangement == true || deferralCode.AccountSource == DeferralAccountSource.Item ? PXPersistingCheck.Nothing : PXPersistingCheck.NullOrBlank); PXDefaultAttribute.SetPersistingCheck <DRDeferredCode.subID>(sender, deferralCode, deferralCode.MultiDeliverableArrangement == true || deferralCode.CopySubFromSourceTran == true ? PXPersistingCheck.Nothing : PXPersistingCheck.NullOrBlank); if (!DeferredMethodType.RequiresTerms(deferralCode) && deferralCode.MultiDeliverableArrangement != true && deferralCode.Occurrences == 0) { sender.RaiseExceptionHandling <DRDeferredCode.occurrences>( e.Row, deferralCode.Occurrences, new PXSetPropertyException(Messages.NoZeroOccurrencesForRecognitionMethod)); } }
/// <summary> /// Checks the presence and consistency of deferral term start / end dates, /// as well as ensures that the document date is no later than the Term End Date /// in case recognizing in past periods is forbidden. /// </summary> /// <param name="deferralSchedule"> /// Deferral schedule from which the document date will be taken. /// </param> protected virtual void ValidateTerms(DRSchedule deferralSchedule) { if (!DeferredMethodType.RequiresTerms(_code)) { return; } if (!deferralSchedule.TermStartDate.HasValue || !deferralSchedule.TermEndDate.HasValue) { throw new PXException(Messages.CannotGenerateTransactionsWithoutTerms); } if (deferralSchedule.TermStartDate > deferralSchedule.TermEndDate) { throw new PXException( Messages.TermCantBeNegative, deferralSchedule.TermEndDate, deferralSchedule.TermStartDate); } }
protected virtual void DRDeferredCode_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { var code = e.Row as DRDeferredCode; if (code == null) { return; } PXUIFieldAttribute.SetVisible(sender, code, null, true); SetPeriodicallyControlsState(sender, code); var accountIsOptional = code.MultiDeliverableArrangement == true || code.AccountSource == DeferralAccountSource.Item; var subIsOptional = code.MultiDeliverableArrangement == true || code.CopySubFromSourceTran == true; PXDefaultAttribute.SetPersistingCheck <DRDeferredCode.accountID>(sender, code, accountIsOptional ? PXPersistingCheck.Nothing : PXPersistingCheck.NullOrBlank); PXDefaultAttribute.SetPersistingCheck <DRDeferredCode.subID>(sender, code, subIsOptional ? PXPersistingCheck.Nothing : PXPersistingCheck.NullOrBlank); bool isFlexible = DeferredMethodType.RequiresTerms(code); PXUIFieldAttribute.SetEnabled <DRDeferredCode.accountType>(sender, code, !isFlexible && code.Method != DeferredMethodType.CashReceipt); PXUIFieldAttribute.SetEnabled <DRDeferredCode.startOffset>(sender, code, !isFlexible); PXUIFieldAttribute.SetEnabled <DRDeferredCode.occurrences>(sender, code, !isFlexible); PXUIFieldAttribute.SetEnabled <DRDeferredCode.deferralSubMaskAR>(sender, code, code.CopySubFromSourceTran != true); PXUIFieldAttribute.SetEnabled <DRDeferredCode.deferralSubMaskAP>(sender, code, code.CopySubFromSourceTran != true); PXUIFieldAttribute.SetVisible <DRDeferredCode.deferralSubMaskAR>(sender, code, code.AccountType == DeferredAccountType.Income); PXUIFieldAttribute.SetVisible <DRDeferredCode.deferralSubMaskAP>(sender, code, code.AccountType == DeferredAccountType.Expense); PXUIFieldAttribute.SetVisible <DRDeferredCode.recognizeInPastPeriods>(sender, code, isFlexible); if (code.MultiDeliverableArrangement == true) { PXUIFieldAttribute.SetVisible(sender, code, null, false); PXUIFieldAttribute.SetVisible <DRDeferredCode.deferredCodeID>(sender, code, true); PXUIFieldAttribute.SetVisible <DRDeferredCode.description>(sender, code, true); PXUIFieldAttribute.SetVisible <DRDeferredCode.multiDeliverableArrangement>(sender, code, true); } }
public virtual IList <DRScheduleTran> GenerateTransactions( DRSchedule deferralSchedule, DRScheduleDetail scheduleDetail, int?branchID) { if (deferralSchedule == null) { throw new ArgumentNullException(nameof(deferralSchedule)); } if (scheduleDetail == null) { throw new ArgumentNullException(nameof(scheduleDetail)); } ValidateTerms(deferralSchedule); decimal defAmount = scheduleDetail.TotalAmt.Value; List <DRScheduleTran> list = new List <DRScheduleTran>(); short lineCounter = 0; if (_code.ReconNowPct.Value > 0) { decimal recNowRaw = defAmount * _code.ReconNowPct.Value * 0.01m; decimal recNow = _roundingFunction(recNowRaw); defAmount -= recNow; lineCounter++; DRScheduleTran nowTran = new DRScheduleTran { BranchID = branchID, AccountID = scheduleDetail.AccountID, SubID = scheduleDetail.SubID, Amount = recNow, RecDate = deferralSchedule.DocDate, FinPeriodID = scheduleDetail.FinPeriodID, LineNbr = lineCounter, ScheduleID = scheduleDetail.ScheduleID, ComponentID = scheduleDetail.ComponentID, Status = _code.Method == DeferredMethodType.CashReceipt ? DRScheduleTranStatus.Projected : DRScheduleTranStatus.Open, }; list.Add(nowTran); } bool isFlexibleDeferralCode = DeferredMethodType.RequiresTerms(_code.Method); DateTime documentDate = deferralSchedule.DocDate.Value; string documentFinPeriod = _financialPeriodProvider.FindFinPeriodByDate(_graph, documentDate)?.FinPeriodID; int occurrences = isFlexibleDeferralCode ? CalcOccurrences(deferralSchedule.TermStartDate.Value, deferralSchedule.TermEndDate.Value) : _code.Occurrences.Value; List <DRScheduleTran> deferredList = new List <DRScheduleTran>(_code.Occurrences.Value); string deferredPeriod = null; for (int i = 0; i < occurrences; i++) { try { if (deferredPeriod == null) { deferredPeriod = isFlexibleDeferralCode ? _financialPeriodProvider.FindFinPeriodByDate(_graph, deferralSchedule.TermStartDate.Value)?.FinPeriodID : _financialPeriodProvider.PeriodPlusPeriod(_graph, scheduleDetail.FinPeriodID, _code.StartOffset.Value); } else { deferredPeriod = _financialPeriodProvider.PeriodPlusPeriod(_graph, deferredPeriod, _code.Frequency.Value); } } catch (PXFinPeriodException ex) { throw new PXException(ex, Messages.NoFinPeriod, _code.DeferredCodeID); } lineCounter++; DateTime recognitionDate = GetRecognitionDate( deferredPeriod, minimumDate: isFlexibleDeferralCode ? deferralSchedule.TermStartDate.Value : documentDate, maximumDate: isFlexibleDeferralCode ? deferralSchedule.TermEndDate : null); DRScheduleTran deferralTransaction = new DRScheduleTran { BranchID = branchID, AccountID = scheduleDetail.AccountID, SubID = scheduleDetail.SubID, RecDate = recognitionDate, FinPeriodID = _financialPeriodProvider.FindFinPeriodByDate(_graph, recognitionDate)?.FinPeriodID, LineNbr = lineCounter, ScheduleID = scheduleDetail.ScheduleID, ComponentID = scheduleDetail.ComponentID, Status = _code.Method == DeferredMethodType.CashReceipt ? DRScheduleTranStatus.Projected : DRScheduleTranStatus.Open }; deferredList.Add(deferralTransaction); } SetAmounts(deferredList, defAmount, deferralSchedule); if (DeferredMethodType.RequiresTerms(_code) && _code.RecognizeInPastPeriods != true) { // Adjust recognition dates and financial periods // that are in the past relative to the document date. // - foreach (DRScheduleTran transaction in deferredList .Where(transaction => transaction.RecDate < documentDate)) { transaction.RecDate = documentDate; transaction.FinPeriodID = documentFinPeriod; } } list.AddRange(deferredList); return(list); }
public virtual IList <DRScheduleTran> GenerateTransactions( DRSchedule deferralSchedule, DRScheduleDetail scheduleDetail) { if (deferralSchedule == null) { throw new ArgumentNullException(nameof(deferralSchedule)); } if (scheduleDetail == null) { throw new ArgumentNullException(nameof(scheduleDetail)); } if (PXAccess.FeatureInstalled <CS.FeaturesSet.aSC606>()) { ValidateTerms(scheduleDetail); } else { ValidateTerms(deferralSchedule); } int? organizationID = PXAccess.GetParentOrganizationID(scheduleDetail.BranchID); decimal defAmount = scheduleDetail.TotalAmt.Value; List <DRScheduleTran> list = new List <DRScheduleTran>(); short lineCounter = 0; if (_code.ReconNowPct.Value > 0) { decimal recNowRaw = defAmount * _code.ReconNowPct.Value * 0.01m; decimal recNow = _roundingFunction(recNowRaw); defAmount -= recNow; lineCounter++; DRScheduleTran nowTran = new DRScheduleTran { BranchID = scheduleDetail.BranchID, AccountID = scheduleDetail.AccountID, SubID = scheduleDetail.SubID, Amount = recNow, RecDate = deferralSchedule.DocDate, FinPeriodID = scheduleDetail.FinPeriodID, TranPeriodID = scheduleDetail.TranPeriodID, LineNbr = lineCounter, DetailLineNbr = scheduleDetail.DetailLineNbr, ScheduleID = scheduleDetail.ScheduleID, ComponentID = scheduleDetail.ComponentID, Status = GetStatus(), }; list.Add(nowTran); } bool isFlexibleDeferralCode = DeferredMethodType.RequiresTerms(_code.Method); DateTime?termStartDate = null; DateTime?termEndDate = null; if (isFlexibleDeferralCode) { bool isASC606 = PXAccess.FeatureInstalled <CS.FeaturesSet.aSC606>(); termStartDate = isASC606 ? scheduleDetail.TermStartDate.Value : deferralSchedule.TermStartDate.Value; termEndDate = isASC606 ? scheduleDetail.TermEndDate.Value : deferralSchedule.TermEndDate.Value; } DateTime documentDate = deferralSchedule.DocDate.Value; FinPeriod documentFinPeriod = _finPeriodRepository.FindFinPeriodByDate(documentDate, organizationID); int occurrences = isFlexibleDeferralCode ? CalcOccurrences(termStartDate.Value, termEndDate.Value, organizationID) : _code.Occurrences.Value; List <DRScheduleTran> deferredList = new List <DRScheduleTran>(_code.Occurrences.Value); FinPeriod deferredPeriod = null; for (int i = 0; i < occurrences; i++) { try { if (deferredPeriod == null) { deferredPeriod = isFlexibleDeferralCode ? _finPeriodRepository.FindFinPeriodByDate(termStartDate, organizationID): _finPeriodRepository.GetOffsetPeriod(scheduleDetail.FinPeriodID, _code.StartOffset.Value, organizationID); } else { deferredPeriod = _finPeriodRepository.GetOffsetPeriod(deferredPeriod.FinPeriodID, _code.Frequency.Value, organizationID); } } catch (PXFinPeriodException ex) { throw new PXException(ex, Messages.NoFinPeriod, _code.DeferredCodeID); } lineCounter++; DateTime recognitionDate = GetRecognitionDate( deferredPeriod.FinPeriodID, minimumDate: isFlexibleDeferralCode ? termStartDate.Value : documentDate, maximumDate: isFlexibleDeferralCode ? termEndDate : null, organizationID: organizationID); FinPeriod finPeriod = _finPeriodRepository.FindFinPeriodByDate(recognitionDate, organizationID); DRScheduleTran deferralTransaction = new DRScheduleTran { BranchID = scheduleDetail.BranchID, AccountID = scheduleDetail.AccountID, SubID = scheduleDetail.SubID, RecDate = recognitionDate, FinPeriodID = finPeriod?.FinPeriodID, TranPeriodID = finPeriod?.MasterFinPeriodID, LineNbr = lineCounter, DetailLineNbr = scheduleDetail.DetailLineNbr, ScheduleID = scheduleDetail.ScheduleID, ComponentID = scheduleDetail.ComponentID, Status = GetStatus(), }; deferredList.Add(deferralTransaction); } SetAmounts(deferredList, defAmount, deferralSchedule.DocDate, termStartDate, termEndDate, organizationID); if (DeferredMethodType.RequiresTerms(_code) && _code.RecognizeInPastPeriods != true) { // Adjust recognition dates and financial periods // that are in the past relative to the document date. // - foreach (DRScheduleTran transaction in deferredList .Where(transaction => transaction.RecDate < documentDate)) { transaction.RecDate = documentDate; transaction.FinPeriodID = documentFinPeriod?.FinPeriodID; transaction.TranPeriodID = documentFinPeriod?.MasterFinPeriodID; } } list.AddRange(deferredList); return(list); }