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 virtual void GenerateProc(Schedule s, short Times, DateTime runDate) { string LastBatchNbr = "0000000000"; Int64 LastInfoID = -1; List <ScheduleDet> sd = MakeSchedule(s, Times, runDate); using (PXTransactionScope ts = new PXTransactionScope()) { foreach (ScheduleDet d in sd) { foreach (BatchNew b in PXSelect <BatchNew, Where <BatchNew.scheduleID, Equal <Optional <Schedule.scheduleID> >, And <BatchNew.scheduled, Equal <boolTrue> > > > .Select(this, s.ScheduleID)) { BatchNew copy = PXCache <BatchNew> .CreateCopy(b); 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, b.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 = "B"; copy.Scheduled = false; copy.DateEntered = d.ScheduledDate; copy.FinPeriodID = d.ScheduledPeriod; 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.SetNote(Batch_Created.Cache, copy, PXNoteAttribute.GetNote(Caches[typeof(BatchNew)], b)); PXNoteAttribute.SetFileNotes(Batch_Created.Cache, copy, PXNoteAttribute.GetFileNotes(Caches[typeof(BatchNew)], b)); foreach (GLTranNew tran in PXSelect <GLTranNew, Where <GLTranNew.module, Equal <Required <GLTranNew.module> >, And <GLTranNew.batchNbr, Equal <Required <GLTranNew.batchNbr> > > > > .Select(this, b.Module, b.BatchNbr)) { GLTranNew trancopy = PXCache <GLTranNew> .CreateCopy(tran); trancopy.OrigBatchNbr = trancopy.BatchNbr; trancopy.OrigModule = trancopy.Module; trancopy.BatchNbr = copy.BatchNbr; trancopy.RefBatchNbr = copy.RefBatchNbr; trancopy.CuryInfoID = copy.CuryInfoID; trancopy.CATranID = null; trancopy.TranDate = d.ScheduledDate; trancopy.FinPeriodID = d.ScheduledPeriod; trancopy.TranPeriodID = d.ScheduledPeriod; Tran_Created.Cache.Insert(trancopy); } } s.LastRunDate = d.ScheduledDate; Running_Schedule.Cache.Update(s); } Running_Schedule.Cache.Persist(PXDBOperation.Update); Batch_Created.Cache.Persist(PXDBOperation.Insert); Batch_Created.Cache.Persist(PXDBOperation.Update); foreach (GLTranNew tran in Tran_Created.Cache.Inserted) { foreach (BatchNew batch in Batch_Created.Cache.Cached) { if (object.Equals(batch.RefBatchNbr, tran.RefBatchNbr)) { tran.BatchNbr = batch.BatchNbr; tran.CuryInfoID = batch.CuryInfoID; if (!string.IsNullOrEmpty(batch.RefNbr)) { tran.RefNbr = batch.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); }