public virtual IEnumerable nextperiod(PXAdapter adapter) { InventoryTranByAcctEnqFilter filter = Filter.Current as InventoryTranByAcctEnqFilter; FinPeriod nextperiod = FinPeriodRepository.FindNextPeriod(FinPeriod.organizationID.MasterValue, filter.FinPeriodID, looped: true); filter.FinPeriodID = nextperiod?.FinPeriodID; ResetFilterDates(filter); return(adapter.Get()); }
protected virtual void InventoryTranByAcctEnqFilter_PeriodEndDate_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e) { var row = e.Row as InventoryTranByAcctEnqFilter; if (row != null) { FinPeriod period = FinPeriodRepository.FindByID(FinPeriod.organizationID.MasterValue, row.FinPeriodID); e.NewValue = period?.EndDate; } }
protected virtual void ResetFilterDates(InventoryTranByAcctEnqFilter aRow) { FinPeriod period = FinPeriodRepository.FindByID(FinPeriod.organizationID.MasterValue, aRow.FinPeriodID); if (period != null) { aRow.PeriodStartDate = period.StartDate; aRow.PeriodEndDate = period.EndDate; aRow.EndDate = null; aRow.StartDate = null; } }
protected virtual OrganizationFinYear GenerateNextOrganizationFinYear(OrganizationFinYear year) { string generatedYearNumber = $"{int.Parse(year.Year) + 1:0000}"; MasterFinYear masterFinYear; while ((masterFinYear = FinPeriodRepository.FindMasterFinYearByID(generatedYearNumber, clearQueryCache: true)) == null) { MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), int.Parse(generatedYearNumber)); } short generatedFinPeriodsCount = (short)masterFinYear.FinPeriods; if (YearSetup.Current.HasAdjustmentPeriod == true) { generatedFinPeriodsCount--; } OrganizationFinPeriod lastNonAdjustmentOrgFinPeriod = this.FinPeriodRepository.FindLastNonAdjustmentOrganizationFinPeriodOfYear(year.OrganizationID, year.Year, clearQueryCache: true); int generatedMasterYearNumber = int.Parse(lastNonAdjustmentOrgFinPeriod.FinYear); List <MasterFinPeriod> masterFinPeriods; PXSelectBase <MasterFinPeriod> select = new PXSelectReadonly < MasterFinPeriod, Where <MasterFinPeriod.finPeriodID, Greater <Required <MasterFinPeriod.finPeriodID> >, And <MasterFinPeriod.startDate, NotEqual <MasterFinPeriod.endDate> > >, OrderBy < Asc <MasterFinPeriod.finPeriodID> > >(this); select.View.Clear(); while ((masterFinPeriods = select .SelectWindowed(0, generatedFinPeriodsCount, lastNonAdjustmentOrgFinPeriod.MasterFinPeriodID) .RowCast <MasterFinPeriod>() .ToList()).Count < generatedFinPeriodsCount) { generatedMasterYearNumber++; MasterCalendarGraph.Clear(); MasterCalendarGraph.GenerateCalendar( FinPeriod.organizationID.MasterValue, int.Parse(FinPeriodRepository.FindLastYear(FinPeriod.organizationID.MasterValue, clearQueryCache: true).Year), generatedMasterYearNumber); select.View.Clear(); } MasterFinPeriod startMasterFinPeriod = masterFinPeriods.First(); return(GenerateSingleOrganizationFinYear((int)year.OrganizationID, masterFinYear, startMasterFinPeriod)); }
public virtual IEnumerable NextPeriod(PXAdapter adapter) { DiscrepancyEnqFilter filter = Filter.Current as DiscrepancyEnqFilter; filter.UseMasterCalendar = filter.OrganizationID == null && filter.BranchID == null; int?calendarOrganizationID = FinPeriodRepository.GetCalendarOrganizationID(filter.OrganizationID, filter.BranchID, filter.UseMasterCalendar); FinPeriod nextPeriodFrom = FinPeriodRepository.FindNextPeriod(calendarOrganizationID, filter.PeriodFrom, looped: true); filter.PeriodFrom = nextPeriodFrom != null ? nextPeriodFrom.FinPeriodID : null; FinPeriod nextPeriodTo = FinPeriodRepository.FindNextPeriod(calendarOrganizationID, filter.PeriodTo, looped: true); filter.PeriodTo = nextPeriodTo != null ? nextPeriodTo.FinPeriodID : null; filter.FilterDetails = null; return(adapter.Get()); }
public virtual IEnumerable nextperiod(PXAdapter adapter) { AccountByYearFilter filter = CurrentFilter; int?calendarOrganizationID = FinPeriodRepository.GetCalendarOrganizationID(filter.OrganizationID, filter.BranchID, filter.UseMasterCalendar); FinYear nextperiod = PXSelect < FinYear, Where <FinYear.year, Greater <Required <AccountByYearFilter.finYear> >, And <FinYear.organizationID, Equal <Required <AccountByYearFilter.organizationID> > > >, OrderBy < Asc <FinYear.year> > > .Select(this, filter.FinYear, calendarOrganizationID) ?? PXSelect < FinYear, Where <FinYear.organizationID, Equal <Required <AccountByYearFilter.organizationID> > >, OrderBy < Asc <FinYear.year> > > .Select(this, calendarOrganizationID); filter.FinYear = nextperiod?.Year; return(adapter.Get()); }
public virtual ProcessingResult CheckFinPeriod(string finPeriodID, int?branchID) { ProcessingResult result = new ProcessingResult(); int? organizationID = PXAccess.GetParentOrganizationID(branchID); FinPeriod period = FinPeriodRepository.FindByID(organizationID, finPeriodID); if (period == null) { result.AddErrorMessage(GL.Messages.FinPeriodDoesNotExistForCompany, FinPeriodIDFormattingAttribute.FormatForError(finPeriodID), PXAccess.GetOrganizationCD(PXAccess.GetParentOrganizationID(branchID))); } else { result = FinPeriodUtils.CanPostToPeriod(period); } if (!result.IsSuccess) { PXProcessing <THistory> .SetError(new PXException(result.GetGeneralMessage())); } return(result); }
public virtual void GenerateCalendar(int?organizationID, int fromYear, int toYear) { (int firstYearNumber, int lastYearNumber) = FinPeriodUtils.GetFirstLastYearForGeneration(organizationID, fromYear, toYear, clearQueryCache: true); OrganizationFinYear firstFinYear = FinPeriodRepository.FindOrganizationFinYearByID(organizationID, $"{firstYearNumber:0000}", clearQueryCache: true); OrganizationFinYear lastFinYear = FinPeriodRepository.FindOrganizationFinYearByID(organizationID, $"{lastYearNumber:0000}", clearQueryCache: true); OrganizationFinYear baseFinYear = firstFinYear; using (PXTransactionScope ts = new PXTransactionScope()) { if (fromYear < firstYearNumber) { do { baseFinYear = GeneratePreviousOrganizationFinYear(baseFinYear); Actions.PressSave(); }while (baseFinYear != null && string.CompareOrdinal(baseFinYear.Year, $"{fromYear:0000}") > 0); } baseFinYear = lastFinYear; if (toYear > lastYearNumber) { do { baseFinYear = GenerateNextOrganizationFinYear(baseFinYear); Actions.PressSave(); }while (baseFinYear != null && string.CompareOrdinal(baseFinYear.Year, $"{toYear:0000}") < 0); } ts.Complete(); } }
protected virtual OrganizationFinPeriod GenerateAdjustmentOrganizationFinPeriod(int organizationID, OrganizationFinPeriod prevFinPeriod) { (string masterYearNumber, string masterPeriodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID); MasterFinYear masterFinYear = FinPeriodRepository.FindMasterFinYearByID(masterYearNumber, clearQueryCache: true); string adjustmentMasterFinPeriodID = $"{masterYearNumber:0000}{masterFinYear.FinPeriods:00}"; (string yearNumber, string periodNumber) = FinPeriodUtils.ParseFinPeriodID(prevFinPeriod.FinPeriodID); periodNumber = $"{int.Parse(periodNumber) + 1:00}"; OrganizationFinPeriod orgFinPeriod = new OrganizationFinPeriod { OrganizationID = organizationID, FinPeriodID = FinPeriodUtils.ComposeFinPeriodID(yearNumber, periodNumber), MasterFinPeriodID = adjustmentMasterFinPeriodID, FinYear = yearNumber, PeriodNbr = periodNumber, Custom = prevFinPeriod.Custom, DateLocked = prevFinPeriod.DateLocked, StartDate = prevFinPeriod.EndDate, EndDate = prevFinPeriod.EndDate, Status = prevFinPeriod.Status, ARClosed = prevFinPeriod.ARClosed, APClosed = prevFinPeriod.APClosed, FAClosed = prevFinPeriod.FAClosed, CAClosed = prevFinPeriod.CAClosed, INClosed = prevFinPeriod.INClosed, Descr = Messages.AdjustmentPeriod, }; MasterFinPeriod masterFinPeriod = FinPeriodRepository.FindMasterFinPeriodByID(adjustmentMasterFinPeriodID); PXDBLocalizableStringAttribute.CopyTranslations <MasterFinPeriod.descr, OrganizationFinPeriod.descr>(this, masterFinPeriod, orgFinPeriod); return(orgFinPeriod); }
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); }
public void Revalue(RevalueFilter filter, List <RevaluedGLHistory> list) { JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PostGraph pg = PXGraph.CreateInstance <PostGraph>(); PXCache basecache = je.Caches[typeof(AcctHist)]; je.Views.Caches.Add(typeof(AcctHist)); string extRefNbrNumbering = je.CMSetup.Current.ExtRefNbrNumberingID; if (string.IsNullOrEmpty(extRefNbrNumbering) == false) { RevaluationRefNbrHelper helper = new RevaluationRefNbrHelper(extRefNbrNumbering); helper.Subscribe(je); } DocumentList <Batch> created = new DocumentList <Batch>(je); Currency currency = PXSelect <Currency, Where <Currency.curyID, Equal <Required <Currency.curyID> > > > .Select(je, filter.CuryID); bool hasErrors = false; using (PXTransactionScope ts = new PXTransactionScope()) { foreach (RevaluedGLHistory hist in list) { PXProcessing <RevaluedGLHistory> .SetCurrentItem(hist); if (hist.FinPtdRevalued == 0m) { PXProcessing <RevaluedGLHistory> .SetProcessed(); continue; } string FinPeriod = FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(hist.BranchID), filter.FinPeriodID) .Result .FinPeriodID; ProcessingResult result = CheckFinPeriod(FinPeriod, hist.BranchID); if (!result.IsSuccess) { hasErrors = true; continue; } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } Batch cmbatch = created.Find <Batch.branchID>(hist.BranchID) ?? new Batch(); if (cmbatch.BatchNbr == null) { je.Clear(); CurrencyInfo info = new CurrencyInfo(); info.CuryID = hist.CuryID; info.CuryEffDate = hist.CuryEffDate; info.BaseCalc = false; info = je.currencyinfo.Insert(info) ?? info; cmbatch = new Batch(); cmbatch.BranchID = hist.BranchID; cmbatch.Module = "CM"; cmbatch.Status = "U"; cmbatch.AutoReverse = false; cmbatch.Released = true; cmbatch.Hold = false; cmbatch.DateEntered = filter.CuryEffDate; FinPeriodIDAttribute.SetPeriodsByMaster <Batch.finPeriodID>(je.BatchModule.Cache, cmbatch, filter.FinPeriodID); cmbatch.CuryID = hist.CuryID; cmbatch.CuryInfoID = info.CuryInfoID; cmbatch.DebitTotal = 0m; cmbatch.CreditTotal = 0m; cmbatch.Description = filter.Description; je.BatchModule.Insert(cmbatch); CurrencyInfo b_info = je.currencyinfo.Select(); if (b_info != null) { b_info.CuryID = hist.CuryID; b_info.CuryEffDate = hist.CuryEffDate; b_info.CuryRateTypeID = hist.CuryRateTypeID; b_info.CuryRate = hist.CuryRate; b_info.RecipRate = hist.RateReciprocal; b_info.CuryMultDiv = hist.CuryMultDiv; je.currencyinfo.Update(b_info); } } else { if (!je.BatchModule.Cache.ObjectsEqual(je.BatchModule.Current, cmbatch)) { je.Clear(); } je.BatchModule.Current = je.BatchModule.Search <Batch.batchNbr>(cmbatch.BatchNbr, cmbatch.Module); } { GLTran tran = new GLTran(); tran.SummPost = false; tran.AccountID = hist.AccountID; tran.SubID = hist.SubID; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (hist.AccountType == AccountType.Asset || hist.AccountType == AccountType.Expense) { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; } else { tran.DebitAmt = (hist.FinPtdRevalued < 0m) ? -1m * hist.FinPtdRevalued : 0m; tran.CreditAmt = (hist.FinPtdRevalued < 0m) ? 0m : hist.FinPtdRevalued; } tran.TranType = "REV"; tran.TranClass = hist.AccountType; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; FinPeriodIDAttribute.SetPeriodsByMaster <GLTran.finPeriodID>(je.GLTranModuleBatNbr.Cache, tran, filter.FinPeriodID); tran.TranDate = filter.CuryEffDate; tran.CuryInfoID = null; tran.Released = true; tran.ReferenceID = null; tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(); je.GLTranModuleBatNbr.Insert(tran); } foreach (GLTran tran in je.GLTranModuleBatNbr.SearchAll <Asc <GLTran.tranClass> >(new object[] { "G" })) { je.GLTranModuleBatNbr.Delete(tran); } { GLTran tran = new GLTran(); tran.SummPost = true; tran.ZeroPost = false; tran.CuryDebitAmt = 0m; tran.CuryCreditAmt = 0m; if (je.BatchModule.Current.DebitTotal > je.BatchModule.Current.CreditTotal) { tran.AccountID = currency.RevalGainAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalGainSubID>(je, hist.BranchID, currency); tran.DebitAmt = 0m; tran.CreditAmt = (je.BatchModule.Current.DebitTotal - je.BatchModule.Current.CreditTotal); } else { tran.AccountID = currency.RevalLossAcctID; tran.SubID = GainLossSubAccountMaskAttribute.GetSubID <Currency.revalLossSubID>(je, hist.BranchID, currency); tran.DebitAmt = (je.BatchModule.Current.CreditTotal - je.BatchModule.Current.DebitTotal); tran.CreditAmt = 0m; } tran.TranType = "REV"; tran.TranClass = GLTran.tranClass.UnrealizedAndRevaluationGOL; tran.RefNbr = string.Empty; tran.TranDesc = filter.Description; tran.Released = true; tran.ReferenceID = null; je.GLTranModuleBatNbr.Insert(tran); } { AcctHist accthist = new AcctHist(); accthist.BranchID = hist.BranchID; accthist.LedgerID = hist.LedgerID; accthist.AccountID = hist.AccountID; accthist.SubID = hist.SubID; accthist.FinPeriodID = filter.FinPeriodID; accthist.CuryID = hist.CuryID; accthist.BalanceType = "A"; accthist = (AcctHist)basecache.Insert(accthist); accthist.FinPtdRevalued += hist.FinPtdRevalued; } PXProcessing <RevaluedGLHistory> .SetProcessed(); } if (je.GLTranModuleBatNbr.Cache.IsInsertedUpdatedDeleted) { je.Save.Press(); if (created.Find(je.BatchModule.Current) == null) { created.Add(je.BatchModule.Current); } } ts.Complete(); } CMSetup cmsetup = PXSelect <CMSetup> .Select(je); for (int i = 0; i < created.Count; i++) { if (cmsetup.AutoPostOption == true) { pg.Clear(); pg.PostBatchProc(created[i]); } } if (hasErrors) { //Clean current to prevent set exception to the last item PXProcessing <RevaluedGLHistory> .SetCurrentItem(null); throw new PXException(ErrorMessages.SeveralItemsFailed); } if (created.Count > 0) { je.BatchModule.Current = created[created.Count - 1]; throw new PXRedirectRequiredException(je, "Preview"); } decimal val = 0m; foreach (RevaluedGLHistory res in GLAccountList.Cache.Updated) { if ((bool)res.Selected) { decimal sign = AccountRules.IsDEALAccount(res.AccountType) ? 1.0m : -1.0m; val += sign * (decimal)res.FinPtdRevalued; } } if (val == 0) { throw new PXOperationCompletedWithWarningException(Messages.NoRevaluationEntryWasMade); } }
public virtual void GenerateProc(Schedule schedule, short times, DateTime runDate) { IEnumerable <ScheduleDet> occurrences = new Scheduler(this).MakeSchedule(schedule, times, runDate); APInvoiceEntry invoiceEntry = CreateGraph(); using (PXTransactionScope transactionScope = new PXTransactionScope()) { foreach (ScheduleDet occurrence in occurrences) { foreach (PXResult <APInvoice, Vendor, CurrencyInfo> scheduledInvoiceResult in PXSelectJoin < APInvoice, InnerJoin <Vendor, On <Vendor.bAccountID, Equal <APInvoice.vendorID> >, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <APInvoice.curyInfoID> > > >, Where < APInvoice.scheduleID, Equal <Required <APInvoice.scheduleID> >, And <APInvoice.scheduled, Equal <boolTrue> > > > .Select(this, schedule.ScheduleID)) { invoiceEntry.Clear(); invoiceEntry.vendor.Current = (Vendor)scheduledInvoiceResult; APInvoice scheduledInvoice = (APInvoice)scheduledInvoiceResult; CurrencyInfo scheduledInvoiceCurrencyInfo = (CurrencyInfo)scheduledInvoiceResult; if (scheduledInvoice.Released == true) { throw new PXException(AR.Messages.ScheduledDocumentAlreadyReleased); } // Cloning currency info is required because we want to preserve // (and not default) the currency rate type of the template document. // - CurrencyInfo newCurrencyInfo = PXCache <CurrencyInfo> .CreateCopy(scheduledInvoiceCurrencyInfo); newCurrencyInfo.CuryInfoID = null; newCurrencyInfo.CuryRate = null; newCurrencyInfo.CuryEffDate = occurrence.ScheduledDate; newCurrencyInfo = invoiceEntry.currencyinfo.Insert(newCurrencyInfo); APInvoice newInvoice = PXCache <APInvoice> .CreateCopy(scheduledInvoice); newInvoice.CuryInfoID = newCurrencyInfo.CuryInfoID; newInvoice.DocDate = occurrence.ScheduledDate; FinPeriod finPeriod = FinPeriodRepository.GetFinPeriodByMasterPeriodID(PXAccess.GetParentOrganizationID(newInvoice.BranchID), occurrence.ScheduledPeriod) .GetValueOrRaiseError(); newInvoice.FinPeriodID = finPeriod.FinPeriodID; newInvoice.TranPeriodID = null; newInvoice.DueDate = null; newInvoice.DiscDate = null; newInvoice.PayDate = null; newInvoice.CuryOrigDiscAmt = null; newInvoice.OrigDiscAmt = null; newInvoice.RefNbr = null; newInvoice.Scheduled = false; newInvoice.CuryLineTotal = 0m; newInvoice.CuryVatTaxableTotal = 0m; newInvoice.CuryVatExemptTotal = 0m; newInvoice.NoteID = null; newInvoice.PaySel = false; newInvoice.IsTaxValid = false; newInvoice.IsTaxPosted = false; newInvoice.IsTaxSaved = false; newInvoice.OrigDocType = scheduledInvoice.DocType; newInvoice.OrigRefNbr = scheduledInvoice.RefNbr; newInvoice = invoiceEntry.Document.Insert(newInvoice); //we insert an item here because we need DontApprove field to be set in RowSelected if (newInvoice.DontApprove != true) { // We always generate documents on hold // if approval process is enabled in AP. // - newInvoice.Hold = true; } newInvoice = invoiceEntry.Document.Update(newInvoice); CurrencyInfoAttribute.SetEffectiveDate <APInvoice.docDate>( invoiceEntry.Document.Cache, new PXFieldUpdatedEventArgs(newInvoice, null, false)); PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(APInvoice)], scheduledInvoice, invoiceEntry.Document.Cache, newInvoice); foreach (APTran originalLine in PXSelect < APTran, Where < APTran.tranType, Equal <Required <APTran.tranType> >, And <APTran.refNbr, Equal <Required <APTran.refNbr> >, And <Where < APTran.lineType, IsNull, Or <APTran.lineType, NotEqual <SOLineType.discount> > > > > > > .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr)) { APTran newLine = PXCache <APTran> .CreateCopy(originalLine); newLine.FinPeriodID = null; newLine.TranPeriodID = null; newLine.RefNbr = null; newLine.CuryInfoID = null; newLine.ManualPrice = true; newLine.ManualDisc = true; newLine.NoteID = null; newLine = invoiceEntry.Transactions.Insert(newLine); PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(APTran)], originalLine, invoiceEntry.Transactions.Cache, newLine); } foreach (APInvoiceDiscountDetail originalDiscountDetail in PXSelect < APInvoiceDiscountDetail, Where < APInvoiceDiscountDetail.docType, Equal <Required <APInvoiceDiscountDetail.docType> >, And <APInvoiceDiscountDetail.refNbr, Equal <Required <APInvoiceDiscountDetail.refNbr> > > > > .Select(invoiceEntry, scheduledInvoice.DocType, scheduledInvoice.RefNbr)) { APInvoiceDiscountDetail newDiscountDetail = PXCache <APInvoiceDiscountDetail> .CreateCopy(originalDiscountDetail); newDiscountDetail.RefNbr = null; newDiscountDetail.CuryInfoID = null; newDiscountDetail.IsManual = true; DiscountEngineProvider.GetEngineFor <APTran, APInvoiceDiscountDetail>().InsertDiscountDetail(invoiceEntry.DiscountDetails.Cache, invoiceEntry.DiscountDetails, newDiscountDetail); } BalanceCalculation.ForceDocumentControlTotals(invoiceEntry, newInvoice); try { invoiceEntry.Save.Press(); } catch { if (invoiceEntry.Document.Cache.IsInsertedUpdatedDeleted) { throw; } } } schedule.LastRunDate = occurrence.ScheduledDate; Running_Schedule.Cache.Update(schedule); } transactionScope.Complete(this); } using (PXTransactionScope ts = new PXTransactionScope()) { Running_Schedule.Cache.Persist(PXDBOperation.Update); ts.Complete(this); } Running_Schedule.Cache.Persisted(false); }
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); }
protected virtual IEnumerable Cancel(PXAdapter a) { string organizationCD; string yearNumber; if (NewCalendarParams.View.Answer == WebDialogResult.None) // First outer call { FinYearKey storedYearKey = new FinYearKey { OrganizationID = OrgFinYear.Current?.OrganizationID, Year = OrgFinYear.Current?.Year }; #region Deliberate Technomagic. Copy-pasted fron base PXCancel instead invocation Clear(); SelectTimeStamp(); #endregion StoredYearKey.Cache.Clear(); StoredYearKey.Insert(storedYearKey); StoredYearKey.Cache.IsDirty = false; organizationCD = (string)a.Searches.GetSearchValueByPosition(0); if (organizationCD == null) { yield break; } yearNumber = (string)a.Searches.GetSearchValueByPosition(1); } else // Second call after SmartPanel closing { object extValue = NewCalendarParams.Cache.GetValueExt <NewOrganizationCalendarParameters.organizationID>(NewCalendarParams.Current); PXFieldState state = extValue as PXFieldState; organizationCD = state != null ? (string)state.Value : (string)extValue; yearNumber = NewCalendarParams.Current.StartYear; } OrganizationFinYear targetYear = PXSelectJoin < OrganizationFinYear, InnerJoin <Organization, On <OrganizationFinYear.organizationID, Equal <Organization.organizationID> > >, Where <Organization.organizationCD, Equal <Required <Organization.organizationCD> >, And <OrganizationFinYear.year, Equal <Required <OrganizationFinYear.year> > > > > .SelectSingleBound(this, new object[] { }, organizationCD, yearNumber); OrganizationFinYear returnYear = null; if (targetYear == null) { OrganizationFinYear lastYear = LastOrganizationYear.SelectSingle(organizationCD); if (lastYear == null) { if (NewCalendarParams.AskExtFullyValid((graph, viewName) => { NewCalendarParams.Current.OrganizationID = PXAccess.GetOrganizationID(organizationCD); }, DialogAnswerType.Positive)) { OrganizationFinYear generatedFinYear; using (PXTransactionScope ts = new PXTransactionScope()) { generatedFinYear = GenerateSingleOrganizationFinYear( (int)NewCalendarParams.Current.OrganizationID, NewCalendarParams.Current.StartYear, NewCalendarParams.Current.StartMasterFinPeriodID); Actions.PressSave(); ts.Complete(); } returnYear = generatedFinYear; } else { OrganizationFinYear storedYear = FinPeriodRepository.FindOrganizationFinYearByID(StoredYearKey.Current?.OrganizationID, StoredYearKey.Current?.Year); returnYear = storedYear; } } else { returnYear = lastYear; } } else { returnYear = targetYear; } if (returnYear != null) { yield return(returnYear); } yield break; }