public static void Run(PMAllocator graph, PMProject item, DateTime?date, DateTime?fromDate, DateTime?toDate) { PXSelectBase <PMTask> select = new PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.allocationID, IsNotNull, And <PMTask.isActive, Equal <True> > > > >(graph); List <PMTask> tasks = new List <PMTask>(); foreach (PMTask pmTask in select.Select(item.ContractID)) { tasks.Add(pmTask); } graph.Clear(); graph.FilterStartDate = fromDate; graph.FilterEndDate = toDate; graph.PostingDate = date; graph.Execute(tasks); if (graph.Document.Current != null) { graph.Actions.PressSave(); PMSetup setup = PXSelect <PMSetup> .Select(graph); PMRegister doc = graph.Caches[typeof(PMRegister)].Current as PMRegister; if (doc != null && setup.AutoReleaseAllocation == true) { RegisterRelease.Release(doc); } } else { throw new PXSetPropertyException(Warnings.NothingToAllocate, PXErrorLevel.RowWarning); } }
public virtual IEnumerable ViewBatch(PXAdapter adapter) { PMRegister row = PXSelect <PMRegister, Where <PMRegister.refNbr, Equal <Current <PMTran.refNbr> >, And <PMRegister.module, Equal <Current <PMTran.tranType> > > > > .Select(this); PXRedirectHelper.TryRedirect(this, row, PXRedirectHelper.WindowMode.NewWindow); return(adapter.Get()); }
/// <summary> /// The key of the dictionary is a BranchID.FinPeriodID key. /// </summary> private Dictionary <string, List <TranInfo> > GetTransByBranchAndFinPeriod(PMRegister doc) { Dictionary <string, List <TranInfo> > transByFinPeriod = new Dictionary <string, List <TranInfo> >(); PXSelectBase <PMTran> select = new PXSelectJoin <PMTran, LeftJoin <Account, On <PMTran.accountID, Equal <Account.accountID> >, InnerJoin <PMProject, On <PMProject.contractID, Equal <PMTran.projectID> >, LeftJoin <PMTask, On <PMTask.projectID, Equal <PMTran.projectID>, And <PMTask.taskID, Equal <PMTran.taskID> > >, LeftJoin <OffsetAccount, On <PMTran.offsetAccountID, Equal <OffsetAccount.accountID> >, LeftJoin <PMAccountGroup, On <PMAccountGroup.groupID, Equal <PMTran.accountGroupID> >, LeftJoin <OffsetPMAccountGroup, On <OffsetPMAccountGroup.groupID, Equal <OffsetAccount.accountGroupID> > > > > > > >, Where <PMTran.tranType, Equal <Required <PMTran.tranType> >, And <PMTran.refNbr, Equal <Required <PMTran.refNbr> > > > >(this); foreach (PXResult <PMTran, Account, PMProject, PMTask, OffsetAccount, PMAccountGroup, OffsetPMAccountGroup> res in select.Select(doc.Module, doc.RefNbr)) { TranInfo tran = new TranInfo(res); string key = string.Format("{0}.{1}.{2}", tran.Tran.BranchID.GetValueOrDefault(), tran.Tran.FinPeriodID, tran.Tran.TranCuryID); if (transByFinPeriod.ContainsKey(key)) { transByFinPeriod[key].Add(tran); } else { List <TranInfo> list = new List <TranInfo>(); list.Add(tran); transByFinPeriod.Add(key, list); } } return(transByFinPeriod); }
public static void ReverseAllocatedTran(PMTran tran) { RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>(); pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert(); reversalDoc.OrigDocType = PMOrigDocType.AllocationReversal; reversalDoc.OrigDocNbr = tran.RefNbr; reversalDoc.Description = "Allocation Reversal to Non-Billable"; pmEntry.Document.Current = reversalDoc; PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>(); foreach (PMTran reverse in engine.ReverseTran(tran)) { reverse.Reversed = true; pmEntry.Transactions.Insert(reverse); } tran.Reversed = true; pmEntry.Transactions.Update(tran); pmEntry.Save.Press(); PMSetup setup = PXSelect <PMSetup> .Select(pmEntry); if (setup.AutoReleaseAllocation == true) { RegisterRelease.Release(reversalDoc); } }
public static void Release(PMRegister doc) { List <PMRegister> list = new List <PMRegister>(); list.Add(doc); Release(list, false); }
public virtual void ViewOrigDocument() { PMRegister doc = PXSelect <PMRegister, Where <PMRegister.refNbr, Equal <Current <PMTran.refNbr> > > > .Select(this); var helper = new EntityHelper(this); if (doc.OrigNoteID.HasValue) { helper.NavigateToRow(doc.OrigNoteID.Value, PXRedirectHelper.WindowMode.NewWindow); } }
protected virtual void _(Events.RowDeleted <ARInvoice> e) { var select = new PXSelectJoin <PMBillingRecord, LeftJoin <PMProforma, On <PMBillingRecord.proformaRefNbr, Equal <PMProforma.refNbr> > >, Where <PMBillingRecord.aRDocType, Equal <Required <PMBillingRecord.aRDocType> >, And <PMBillingRecord.aRRefNbr, Equal <Required <PMBillingRecord.aRRefNbr> > > > >(Base); var resultset = select.Select(e.Row.DocType, e.Row.RefNbr); if (resultset.Count > 0) { PMBillingRecord billingRecord = PXResult.Unwrap <PMBillingRecord>(resultset[0]); if (billingRecord != null) { if (billingRecord.ProformaRefNbr != null) { billingRecord.ARDocType = null; billingRecord.ARRefNbr = null; ProjectBillingRecord.Update(billingRecord); PMProforma proforma = PXResult.Unwrap <PMProforma>(resultset[0]); if (proforma != null && !string.IsNullOrEmpty(proforma.RefNbr)) { proforma.ARInvoiceDocType = null; proforma.ARInvoiceRefNbr = null; proforma.Released = false; proforma.Status = ProformaStatus.Open; ProjectProforma.Update(proforma); } } else { ProjectBillingRecord.Delete(billingRecord); } } PMRegister allocationReversal = PXSelect <PMRegister, Where <PMRegister.origDocType, Equal <PMOrigDocType.allocationReversal>, And <PMRegister.origNoteID, Equal <Required <ARInvoice.noteID> >, And <PMRegister.released, Equal <False> > > > > .Select(Base, e.Row.NoteID); if (allocationReversal != null) { ProjectRegister.Delete(allocationReversal); } } AddToUnbilledSummary(e.Row); }
public static void ReverseAllocatedTran(PMTran tran) { RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>(); pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert(); reversalDoc.OrigDocType = PMOrigDocType.AllocationReversal; reversalDoc.OrigDocNbr = tran.RefNbr; reversalDoc.Description = PXMessages.LocalizeNoPrefix(Messages.AllocationReversalNonBilling); pmEntry.Document.Current = reversalDoc; PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>(); foreach (PMTran reverse in engine.ReverseTran(tran)) { reverse.Reversed = true; reverse.Date = null; reverse.FinPeriodID = null; reverse.TranDate = null; reverse.TranPeriodID = null; pmEntry.Transactions.Insert(reverse); } tran.Reversed = true; PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran); pmEntry.Transactions.Update(tran); pmEntry.Save.Press(); PMSetup setup = PXSelect <PMSetup> .Select(pmEntry); if (setup.AutoReleaseAllocation == true) { RegisterRelease.Release(reversalDoc); } }
public static void Run(PMAllocator graph, PMTask item, DateTime?date, DateTime?fromDate, DateTime?toDate) { graph.Clear(); graph.FilterStartDate = fromDate; graph.FilterEndDate = toDate; graph.Execute(item); if (graph.Document.Current != null) { graph.Actions.PressSave(); PMSetup setup = PXSelect <PMSetup> .Select(graph); PMRegister doc = graph.Caches[typeof(PMRegister)].Current as PMRegister; if (doc != null && setup.AutoReleaseAllocation == true) { RegisterRelease.Release(doc); } } else { throw new PXSetPropertyException(Warnings.NothingToAllocate, PXErrorLevel.RowWarning); } }
public static void ReverseAllocatedTran(PMTran tran) { RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>(); pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); PMRegister origDoc = PXSelectReadonly <PMRegister, Where <PMRegister.refNbr, Equal <Required <PMRegister.refNbr> > > > .Select(pmEntry, tran.RefNbr); PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert(); reversalDoc.OrigDocType = PMOrigDocType.Reversal; reversalDoc.OrigNoteID = origDoc.NoteID; reversalDoc.Description = PXMessages.LocalizeNoPrefix(Messages.AllocationReversal); pmEntry.Document.Current = reversalDoc; PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>(); foreach (PMTran reverse in engine.ReverseTran(tran)) { pmEntry.Transactions.Insert(reverse); } tran.ExcludedFromBilling = true; tran.ExcludedFromBillingReason = PXMessages.LocalizeNoPrefix(Messages.ExcludedFromBillingAsReversed); PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran); pmEntry.Transactions.Update(tran); pmEntry.Save.Press(); PMSetup setup = PXSelect <PMSetup> .Select(pmEntry); if (setup.AutoReleaseAllocation == true) { RegisterRelease.Release(reversalDoc); } }
public virtual bool Bill(int?projectID, DateTime?invoiceDate) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, projectID); ContractBillingSchedule schedule = PXSelect <ContractBillingSchedule> .Search <ContractBillingSchedule.contractID>(this, project.ContractID); DateTime billingDate; if (invoiceDate == null) { if (schedule.Type == BillingType.OnDemand) { billingDate = Accessinfo.BusinessDate ?? DateTime.Now; } else { billingDate = schedule.NextDate.Value; } } else { billingDate = invoiceDate.Value; } Customer customer = null; if (project.CustomerID != null) { customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(this, project.CustomerID); } if (customer == null) { throw new PXException(Messages.NoCustomer); } List <BillingData> list = new List <BillingData>(); List <PMTran> reversalTrans = new List <PMTran>(); PXSelectBase <PMTask> selectTasks = new PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.billingID, IsNotNull, And <PMTask.isActive, Equal <True> > > > >(this); foreach (PMTask task in selectTasks.Select(project.ContractID)) { if ((task.BillingOption == PMBillingOption.OnTaskCompletion && task.IsCompleted == true) || (task.BillingOption == PMBillingOption.OnProjectCompetion && project.IsCompleted == true) || task.BillingOption == PMBillingOption.OnBilling) { list.AddRange(BillTask(task, billingDate)); reversalTrans.AddRange(ReverseWipTask(task, billingDate)); } } //Regroup by Invoices: Dictionary <string, List <BillingData> > invoices = new Dictionary <string, List <BillingData> >(); string emptyInvoiceDescriptionKey = "!@#$%^&"; foreach (BillingData data in list) { if (string.IsNullOrEmpty(data.Rule.InvoiceDescription)) { if (invoices.ContainsKey(emptyInvoiceDescriptionKey)) { invoices[emptyInvoiceDescriptionKey].Add(data); } else { invoices.Add(emptyInvoiceDescriptionKey, new List <BillingData>(new BillingData[] { data })); } } else { if (invoices.ContainsKey(data.Rule.InvoiceDescription)) { invoices[data.Rule.InvoiceDescription].Add(data); } else { invoices.Add(data.Rule.InvoiceDescription, new List <BillingData>(new BillingData[] { data })); } } //Reverse On Billing: if (data.PMTran != null) { bool reverseOnBilling = false; if (data.PMTran.Reverse == PMReverse.OnBilling) { reverseOnBilling = true; } else if (data.PMTran.Reverse != PMReverse.Never && IsNonGL(data.PMTran)) { reverseOnBilling = true; } if (reverseOnBilling) { reversalTrans.AddRange(ReverseTran(data.PMTran)); } } } //Schedule update: schedule.NextDate = GetNextBillingDate(this, schedule, schedule.NextDate); schedule.LastDate = this.Accessinfo.BusinessDate; BillingSchedule.Update(schedule); //ContractDetail update: PXSelectBase <ContractDetailExt> cis = new PXSelect <ContractDetailExt, Where <ContractDetailExt.contractID, Equal <Required <ContractDetailExt.contractID> >, And <ContractDetailExt.resetUsage, Equal <ResetUsageOption.onBilling> > > >(this); foreach (ContractDetailExt ci in cis.Select(project.ContractID)) { ci.Used = 0; ContractDetail.Update(ci); } List <ARRegister> doclist = new List <ARRegister>(); PMRegister reversalDoc = null; if (invoices.Count > 0) { using (PXTransactionScope ts = new PXTransactionScope()) { ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>(); invoiceEntry.FieldVerifying.AddHandler <ARInvoice.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); invoiceEntry.FieldVerifying.AddHandler <ARTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); invoiceEntry.FieldVerifying.AddHandler <ARTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); foreach (KeyValuePair <string, List <BillingData> > kv in invoices) { invoiceEntry.Clear(PXClearOption.ClearAll); string description = kv.Key == emptyInvoiceDescriptionKey ? null : kv.Key; string docDesc = description ?? string.Format(PXMessages.LocalizeNoPrefix(CT.Messages.BillingFor), project.ContractCD, project.Description); ARInvoice invoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].CreateInstance(); invoice.DocType = GetDocType(kv.Value); int mult = 1; if (invoice.DocType == ARDocType.CreditMemo) { mult = -1; } invoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].Insert(invoice); invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.customerID>(invoice, customer.AcctCD); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.customerLocationID>(invoice, project.LocationID); invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.docDate>(invoice, billingDate); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.docDesc>(invoice, docDesc); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.projectID>(invoice, project.ContractID); CurrencyInfo curyinfo = (CurrencyInfo)invoiceEntry.Caches[typeof(CurrencyInfo)].Current; foreach (BillingData data in kv.Value) { data.Tran.ExtPrice = data.Tran.ExtPrice.GetValueOrDefault() * mult; data.Tran.Qty = data.Tran.Qty.GetValueOrDefault() * mult; data.Tran.TranAmt = data.Tran.TranAmt.GetValueOrDefault() * mult; decimal curyamount; PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, data.Tran.UnitPrice.GetValueOrDefault(), out curyamount); data.Tran.CuryUnitPrice = curyamount; PXDBCurrencyAttribute.CuryConvCury(invoiceEntry.Caches[typeof(CurrencyInfo)], curyinfo, data.Tran.ExtPrice.GetValueOrDefault(), out curyamount); data.Tran.CuryExtPrice = curyamount; data.Tran.CuryTranAmt = data.Tran.CuryExtPrice; data.Tran.FreezeManualDisc = true; data.Tran.CuryInfoID = curyinfo.CuryInfoID; ARTran newTran = (ARTran)invoiceEntry.Caches[typeof(ARTran)].Insert(data.Tran); if (data.Tran.TranAmt > newTran.TranAmt) { newTran.PMDeltaOption = ARTran.pMDeltaOption.CompleteLine; //autocomplete when currency descrepency exists. } if (data.Tran.AccountID != null) { ARTran copy = (ARTran)invoiceEntry.Caches[typeof(ARTran)].CreateCopy(newTran); copy.AccountID = data.Tran.AccountID; copy = (ARTran)invoiceEntry.Caches[typeof(ARTran)].Update(copy); if (data.SubCD != null) { invoiceEntry.Caches[typeof(ARTran)].SetValueExt <ARTran.subID>(copy, data.SubCD); } } if (data.Note != null) { PXNoteAttribute.SetNote(invoiceEntry.Caches[typeof(ARTran)], newTran, data.Note); } if (data.Files != null && data.Files.Length > 0) { PXNoteAttribute.SetFileNotes(invoiceEntry.Caches[typeof(ARTran)], newTran, data.Files); } //item.RefLineNbr = newTran.LineNbr; } ARInvoice oldInvoice = (ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].CreateCopy(invoice); invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoiceEntry.Caches[typeof(ARInvoice)].RaiseRowUpdated(invoice, oldInvoice); invoiceEntry.Caches[typeof(ARInvoice)].SetValue <ARInvoice.curyOrigDocAmt>(invoice, invoice.CuryDocBal); if (project.AutomaticReleaseAR == true) { invoiceEntry.Caches[typeof(ARInvoice)].SetValueExt <ARInvoice.hold>(invoice, false); } doclist.Add((ARInvoice)invoiceEntry.Caches[typeof(ARInvoice)].Current); invoiceEntry.Save.Press(); } Actions.PressSave(); if (reversalTrans.Count > 0) { RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>(); pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); //Project can be completed. pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); //Task can be completed. pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert(); reversalDoc.OrigDocType = PMOrigDocType.AllocationReversal; reversalDoc.Description = "Allocation Reversal on Billing"; pmEntry.Document.Current = reversalDoc; foreach (PMTran tran in reversalTrans) { pmEntry.Transactions.Insert(tran); } pmEntry.Save.Press(); } ts.Complete(); } } else { this.Persist(typeof(ContractBillingSchedule), PXDBOperation.Update); this.Persist(typeof(Contract), PXDBOperation.Update); } if (project.AutomaticReleaseAR == true) { try { ARDocumentRelease.ReleaseDoc(doclist, false); } catch (Exception ex) { throw new PXException(Messages.AutoReleaseARFailed, ex); } if (reversalDoc != null) { try { RegisterRelease.Release(reversalDoc); } catch (Exception ex) { throw new PXException(Messages.AutoReleaseOfReversalFailed, ex); } } } return(doclist.Count > 0); }
public static bool ReleaseWithoutPost(List <PMRegister> list, bool isMassProcess, out List <ProcessInfo <Batch> > infoList) { bool failed = false; infoList = new List <ProcessInfo <Batch> >(); if (!list.Any()) { return(!failed); } RegisterReleaseProcess rg = PXGraph.CreateInstance <RegisterReleaseProcess>(); JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PMAllocator allocator = PXGraph.CreateInstance <PMAllocator>(); //Task may be IsActive=False - it may be completed. User cannot create transactions with this //TaskID. But the system has to process the given task - hence override the FieldVerification in the Selector. je.FieldVerifying.AddHandler <GLTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); je.FieldVerifying.AddHandler <GLTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); for (int i = 0; i < list.Count; i++) { ProcessInfo <Batch> info = new ProcessInfo <Batch>(i); infoList.Add(info); PMRegister doc = list[i]; try { List <PMTask> allocTasks; info.Batches.AddRange(rg.Release(je, doc, out allocTasks)); allocator.Clear(); allocator.TimeStamp = je.TimeStamp; if (allocTasks.Count > 0) { allocator.Execute(allocTasks); allocator.Actions.PressSave(); } if (allocator.Document.Current != null && rg.AutoReleaseAllocation) { List <PMTask> allocTasks2; info.Batches.AddRange(rg.Release(je, allocator.Document.Current, out allocTasks2)); } if (isMassProcess) { PXProcessing <PMRegister> .SetInfo(i, ActionsMessages.RecordProcessed); } } catch (Exception e) { if (isMassProcess) { PXProcessing <PMRegister> .SetError(i, e is PXOuterException?e.Message + "\r\n" + String.Join("\r\n", ((PXOuterException)e).InnerMessages) : e.Message); failed = true; } else { throw new PXMassProcessException(i, e); } } } return(!failed); }
public List <Batch> Release(JournalEntry je, PMRegister doc, out List <PMTask> allocTasks) { doc = OnBeforeRelease(doc); allocTasks = new List <PMTask>(); List <Batch> batches = new List <Batch>(); Dictionary <string, PMTask> tasksToAutoAllocate = new Dictionary <string, PMTask>(); List <PMTran> sourceForAllocation = new List <PMTran>(); Dictionary <string, List <TranInfo> > transByFinPeriod = GetTransByBranchAndFinPeriod(doc); Debug.Assert(transByFinPeriod.Count > 0, "Failed to select transactions by finperiod in PMRegister Release."); ProjectBalance pb = CreateProjectBalance(); using (var ts = new PXTransactionScope()) { foreach (KeyValuePair <string, List <TranInfo> > kv in transByFinPeriod) { string[] parts = kv.Key.Split('.'); int? branchID = parts[0] == "0" ? null : (int?)int.Parse(parts[0]); je.Clear(PXClearOption.ClearAll); CurrencyInfo info = new CurrencyInfo(); info.CuryID = parts[2]; info.CuryEffDate = Accessinfo.BusinessDate; info = je.currencyinfo.Insert(info); Batch newbatch = new Batch(); newbatch.Module = doc.Module; newbatch.Status = BatchStatus.Unposted; newbatch.Released = true; newbatch.Hold = false; newbatch.BranchID = branchID; newbatch.FinPeriodID = parts[1]; newbatch.CuryID = parts[2]; newbatch.CuryInfoID = info.CuryInfoID; newbatch.Description = doc.Description; je.BatchModule.Insert(newbatch); bool tranAdded = false; foreach (TranInfo t in kv.Value) { bool isGL = false; if (t.Tran.Released != true && t.Tran.IsNonGL != true && t.Project.BaseType == CT.CTPRType.Project && !string.IsNullOrEmpty(t.AccountGroup.Type) && t.AccountGroup.Type != PMAccountType.OffBalance && !ProjectDefaultAttribute.IsNonProject(t.Tran.ProjectID) && t.Tran.AccountID != null && t.Tran.SubID != null && t.Tran.OffsetAccountID != null && t.Tran.OffsetSubID != null) { GLTran tran1 = new GLTran(); tran1.TranDate = t.Tran.Date; tran1.TranPeriodID = t.Tran.TranPeriodID; tran1.SummPost = false; tran1.BranchID = t.Tran.BranchID; tran1.PMTranID = t.Tran.TranID; tran1.ProjectID = t.Tran.ProjectID; tran1.TaskID = t.Tran.TaskID; tran1.CostCodeID = t.Tran.CostCodeID; tran1.TranDesc = t.Tran.Description; tran1.ReferenceID = t.Tran.BAccountID; tran1.InventoryID = t.Tran.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID ? null : t.Tran.InventoryID; tran1.Qty = t.Tran.Qty; tran1.UOM = t.Tran.UOM; tran1.TranType = t.Tran.TranType; tran1.CuryInfoID = t.Tran.BaseCuryInfoID; tran1.CuryCreditAmt = 0; tran1.CreditAmt = 0; tran1.CuryDebitAmt = t.Tran.TranCuryAmount; tran1.DebitAmt = t.Tran.Amount; tran1.AccountID = t.Tran.AccountID; tran1.SubID = t.Tran.SubID; tran1.Released = true; je.GLTranModuleBatNbr.Insert(tran1); GLTran tran2 = new GLTran(); tran2.TranDate = t.Tran.Date; tran2.TranPeriodID = t.Tran.TranPeriodID; tran2.SummPost = false; tran2.BranchID = t.Tran.BranchID; tran2.PMTranID = t.Tran.TranID; tran2.ProjectID = t.OffsetAccountGroup.GroupID != null ? t.Tran.ProjectID : ProjectDefaultAttribute.NonProject(); tran2.TaskID = t.OffsetAccountGroup.GroupID != null ? t.Tran.TaskID : null; tran2.CostCodeID = tran2.TaskID != null ? t.Tran.CostCodeID : null; tran2.TranDesc = t.Tran.Description; tran2.ReferenceID = t.Tran.BAccountID; tran2.InventoryID = t.Tran.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID ? null : t.Tran.InventoryID; tran2.Qty = t.Tran.Qty; tran2.UOM = t.Tran.UOM; tran2.TranType = t.Tran.TranType; tran2.CuryInfoID = t.Tran.BaseCuryInfoID; tran2.CuryCreditAmt = t.Tran.TranCuryAmount; tran2.CreditAmt = t.Tran.Amount; tran2.CuryDebitAmt = 0; tran2.DebitAmt = 0; tran2.AccountID = t.Tran.OffsetAccountID; tran2.SubID = t.Tran.OffsetSubID; tran2.Released = true; je.GLTranModuleBatNbr.Insert(tran2); tranAdded = true; isGL = true; t.Tran.BatchNbr = je.BatchModule.Current.BatchNbr; } if (!isGL) { if (t.Tran.AccountGroupID == null && t.Project.BaseType == CT.CTPRType.Project && t.Project.NonProject != true) { throw new PXException(Messages.AccountGroupIsRequired, doc.RefNbr); } } if (t.Tran.ExcludedFromBalance != true) { JournalEntryProjectExt xje = je.GetExtension <JournalEntryProjectExt>(); IList <ProjectBalance.Result> balances = pb.Calculate(t.Project, t.Tran, t.Account, t.AccountGroup, t.OffsetAccount, t.OffsetAccountGroup); foreach (ProjectBalance.Result balance in balances) { if (balance.Status != null) { PMBudgetAccum ps = new PMBudgetAccum(); ps.ProjectID = balance.Status.ProjectID; ps.ProjectTaskID = balance.Status.ProjectTaskID; ps.AccountGroupID = balance.Status.AccountGroupID; ps.InventoryID = balance.Status.InventoryID; ps.CostCodeID = balance.Status.CostCodeID; ps.UOM = balance.Status.UOM; ps.IsProduction = balance.Status.IsProduction; ps.Type = balance.Status.Type; ps.Description = balance.Status.Description; ps.CuryInfoID = balance.Status.CuryInfoID; ps = xje.ProjectBudget.Insert(ps); ps.ActualQty += balance.Status.ActualQty.GetValueOrDefault(); ps.CuryActualAmount += balance.Status.CuryActualAmount.GetValueOrDefault(); ps.ActualAmount += balance.Status.ActualAmount.GetValueOrDefault(); } if (balance.ForecastHistory != null) { PMForecastHistoryAccum forecast = new PMForecastHistoryAccum(); forecast.ProjectID = balance.ForecastHistory.ProjectID; forecast.ProjectTaskID = balance.ForecastHistory.ProjectTaskID; forecast.AccountGroupID = balance.ForecastHistory.AccountGroupID; forecast.InventoryID = balance.ForecastHistory.InventoryID; forecast.CostCodeID = balance.ForecastHistory.CostCodeID; forecast.PeriodID = balance.ForecastHistory.PeriodID; forecast = xje.ForecastHistory.Insert(forecast); forecast.ActualQty += balance.ForecastHistory.ActualQty.GetValueOrDefault(); forecast.CuryActualAmount += balance.ForecastHistory.CuryActualAmount.GetValueOrDefault(); forecast.ActualAmount += balance.ForecastHistory.ActualAmount.GetValueOrDefault(); } if (balance.TaskTotal != null) { PMTaskTotal ta = new PMTaskTotal(); ta.ProjectID = balance.TaskTotal.ProjectID; ta.TaskID = balance.TaskTotal.TaskID; ta = xje.ProjectTaskTotals.Insert(ta); ta.CuryAsset += balance.TaskTotal.CuryAsset.GetValueOrDefault(); ta.Asset += balance.TaskTotal.Asset.GetValueOrDefault(); ta.CuryLiability += balance.TaskTotal.CuryLiability.GetValueOrDefault(); ta.Liability += balance.TaskTotal.Liability.GetValueOrDefault(); ta.CuryIncome += balance.TaskTotal.CuryIncome.GetValueOrDefault(); ta.Income += balance.TaskTotal.Income.GetValueOrDefault(); ta.CuryExpense += balance.TaskTotal.CuryExpense.GetValueOrDefault(); ta.Expense += balance.TaskTotal.Expense.GetValueOrDefault(); } if (!isGL) { foreach (PMHistory item in balance.History) { PMHistoryAccum hist = new PMHistoryAccum(); hist.ProjectID = item.ProjectID; hist.ProjectTaskID = item.ProjectTaskID; hist.AccountGroupID = item.AccountGroupID; hist.InventoryID = item.InventoryID; hist.CostCodeID = item.CostCodeID; hist.PeriodID = item.PeriodID; hist.BranchID = item.BranchID; hist = (PMHistoryAccum)je.Caches[typeof(PMHistoryAccum)].Insert(hist); hist.FinPTDCuryAmount += item.FinPTDCuryAmount.GetValueOrDefault(); hist.FinPTDAmount += item.FinPTDAmount.GetValueOrDefault(); hist.FinYTDCuryAmount += item.FinYTDCuryAmount.GetValueOrDefault(); hist.FinYTDAmount += item.FinYTDAmount.GetValueOrDefault(); hist.FinPTDQty += item.FinPTDQty.GetValueOrDefault(); hist.FinYTDQty += item.FinYTDQty.GetValueOrDefault(); hist.TranPTDCuryAmount += item.TranPTDCuryAmount.GetValueOrDefault(); hist.TranPTDAmount += item.TranPTDAmount.GetValueOrDefault(); hist.TranYTDCuryAmount += item.TranYTDCuryAmount.GetValueOrDefault(); hist.TranYTDAmount += item.TranYTDAmount.GetValueOrDefault(); hist.TranPTDQty += item.TranPTDQty.GetValueOrDefault(); hist.TranYTDQty += item.TranYTDQty.GetValueOrDefault(); } } } } AddToUnbilledSummary(je, t.Tran); t.Tran.Released = true; je.Caches[typeof(PMTran)].Update(t.Tran); sourceForAllocation.Add(t.Tran); if (t.Tran.Allocated != true && t.Tran.ExcludedFromAllocation != true && t.Project.AutoAllocate == true) { if (!tasksToAutoAllocate.ContainsKey(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID))) { tasksToAutoAllocate.Add(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID), t.Task); } } } if (tranAdded) { je.Save.Press(); batches.Add(je.BatchModule.Current); } else { je.Persist(typeof(PMTran), PXDBOperation.Update); je.Persist(typeof(PMBudgetAccum), PXDBOperation.Insert); je.Persist(typeof(PMForecastHistoryAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert); je.Persist(typeof(PMTaskAllocTotalAccum), PXDBOperation.Insert); je.Persist(typeof(PMHistoryAccum), PXDBOperation.Insert); //only non-gl balance is updated je.Persist(typeof(PMUnbilledDailySummaryAccum), PXDBOperation.Insert); je.SelectTimeStamp(); } } allocTasks.AddRange(tasksToAutoAllocate.Values); doc.Released = true; doc.Status = PMRegister.status.Released; je.Caches[typeof(PMRegister)].Update(doc); je.Persist(typeof(PMTran), PXDBOperation.Update); je.Persist(typeof(PMRegister), PXDBOperation.Update); je.Persist(typeof(PMBudgetAccum), PXDBOperation.Insert); je.Persist(typeof(PMForecastHistoryAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskAllocTotalAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert); ts.Complete(); } return(batches); }
public virtual PMRegister OnBeforeRelease(PMRegister doc) { return(doc); }
public List <Batch> Release(JournalEntry je, PMRegister doc, out List <PMTask> allocTasks) { allocTasks = new List <PMTask>(); List <Batch> batches = new List <Batch>(); Dictionary <string, PMTask> tasksToAutoAllocate = new Dictionary <string, PMTask>(); List <PMTran> sourceForAllocation = new List <PMTran>(); Dictionary <string, List <TranInfo> > transByFinPeriod = GetTransByBranchAndFinPeriod(doc); Debug.Assert(transByFinPeriod.Count > 0, "Failed to select transactions by finperiod in PMRegister Release."); using (var ts = new PXTransactionScope()) { foreach (KeyValuePair <string, List <TranInfo> > kv in transByFinPeriod) { string[] parts = kv.Key.Split('.'); int? branchID = parts[0] == "0" ? null : (int?)int.Parse(parts[0]); je.Clear(PXClearOption.ClearAll); Batch newbatch = new Batch(); newbatch.Module = doc.Module; newbatch.Status = BatchStatus.Unposted; newbatch.Released = true; newbatch.Hold = false; newbatch.BranchID = branchID; newbatch.FinPeriodID = parts[1]; newbatch.Description = doc.Description; je.BatchModule.Insert(newbatch); bool tranAdded = false; foreach (TranInfo t in kv.Value) { bool isGL = false; if (t.Tran.Released != true && t.Tran.IsNonGL != true && t.Project.BaseType == PMProject.ProjectBaseType.Project && !string.IsNullOrEmpty(t.AccountGroup.Type) && t.AccountGroup.Type != PMAccountType.OffBalance && !ProjectDefaultAttribute.IsNonProject(this, t.Tran.ProjectID)) { GLTran tran1 = new GLTran(); tran1.TranDate = t.Tran.TranDate; tran1.TranPeriodID = t.Tran.TranPeriodID; tran1.SummPost = false; tran1.BranchID = t.Tran.BranchID; tran1.PMTranID = t.Tran.TranID; tran1.ProjectID = t.Tran.ProjectID; tran1.TaskID = t.Tran.TaskID; tran1.TranDesc = t.Tran.Description; tran1.ReferenceID = t.Tran.BAccountID; tran1.InventoryID = t.Tran.InventoryID == PMProjectStatus.EmptyInventoryID ? null : t.Tran.InventoryID; tran1.Qty = t.Tran.Qty; tran1.UOM = t.Tran.UOM; tran1.TranType = t.Tran.TranType; tran1.CuryCreditAmt = 0; tran1.CreditAmt = 0; tran1.CuryDebitAmt = t.Tran.Amount; tran1.DebitAmt = t.Tran.Amount; tran1.AccountID = t.Tran.AccountID; tran1.SubID = t.Tran.SubID; tran1.Released = true; je.GLTranModuleBatNbr.Insert(tran1); GLTran tran2 = new GLTran(); tran2.TranDate = t.Tran.TranDate; tran2.TranPeriodID = t.Tran.TranPeriodID; tran2.SummPost = false; tran2.BranchID = t.Tran.BranchID; tran2.PMTranID = t.Tran.TranID; tran2.ProjectID = t.OffsetAccountGroup.GroupID != null ? t.Tran.ProjectID : ProjectDefaultAttribute.NonProject(this); tran2.TaskID = t.OffsetAccountGroup.GroupID != null ? t.Tran.TaskID : null; tran2.TranDesc = t.Tran.Description; tran2.ReferenceID = t.Tran.BAccountID; tran2.InventoryID = t.Tran.InventoryID == PMProjectStatus.EmptyInventoryID ? null : t.Tran.InventoryID; tran2.Qty = t.Tran.Qty; tran2.UOM = t.Tran.UOM; tran2.TranType = t.Tran.TranType; tran2.CuryCreditAmt = t.Tran.Amount; tran2.CreditAmt = t.Tran.Amount; tran2.CuryDebitAmt = 0; tran2.DebitAmt = 0; tran2.AccountID = t.Tran.OffsetAccountID; tran2.SubID = t.Tran.OffsetSubID; tran2.Released = true; je.GLTranModuleBatNbr.Insert(tran2); tranAdded = true; isGL = true; t.Tran.BatchNbr = je.BatchModule.Current.BatchNbr; } if (!isGL) { if (t.Tran.AccountGroupID == null && t.Project.BaseType == PMProject.ProjectBaseType.Project && t.Project.NonProject != true) { throw new PXException(Messages.AccountGroupIsRequired, doc.RefNbr); } } IList <PMHistory> historyList = UpdateProjectBalance(je, t.Tran, t.Account, t.AccountGroup, t.OffsetAccount, t.OffsetAccountGroup); if (!isGL) { #region History Update foreach (PMHistory item in historyList) { PMHistoryAccum hist = new PMHistoryAccum(); hist.ProjectID = item.ProjectID; hist.ProjectTaskID = item.ProjectTaskID; hist.AccountGroupID = item.AccountGroupID; hist.InventoryID = item.InventoryID; hist.PeriodID = item.PeriodID; hist = (PMHistoryAccum)je.Caches[typeof(PMHistoryAccum)].Insert(hist); hist.FinPTDAmount += item.FinPTDAmount.GetValueOrDefault(); hist.FinYTDAmount += item.FinYTDAmount.GetValueOrDefault(); hist.FinPTDQty += item.FinPTDQty.GetValueOrDefault(); hist.FinYTDQty += item.FinYTDQty.GetValueOrDefault(); hist.TranPTDAmount += item.TranPTDAmount.GetValueOrDefault(); hist.TranYTDAmount += item.TranYTDAmount.GetValueOrDefault(); hist.TranPTDQty += item.TranPTDQty.GetValueOrDefault(); hist.TranYTDQty += item.TranYTDQty.GetValueOrDefault(); } #endregion } AddToUnbilledSummary(je, t.Tran); t.Tran.Released = true; je.Caches[typeof(PMTran)].Update(t.Tran); sourceForAllocation.Add(t.Tran); if (t.Tran.Allocated != true && t.Project.AutoAllocate == true) { if (!tasksToAutoAllocate.ContainsKey(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID))) { tasksToAutoAllocate.Add(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID), t.Task); } } } if (tranAdded) { je.Persist(typeof(PMHistoryAccum), PXDBOperation.Insert); //only non-gl balance is updated je.Save.Press(); batches.Add(je.BatchModule.Current); } else { je.Persist(typeof(PMTran), PXDBOperation.Update); je.Persist(typeof(PMProjectStatusAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert); je.Persist(typeof(PMHistoryAccum), PXDBOperation.Insert); //only non-gl balance is updated je.Persist(typeof(PMUnbilledDailySummaryAccum), PXDBOperation.Insert); je.SelectTimeStamp(); } } allocTasks.AddRange(tasksToAutoAllocate.Values); doc.Released = true; je.Caches[typeof(PMRegister)].Update(doc); je.Persist(typeof(PMTran), PXDBOperation.Update); je.Persist(typeof(PMRegister), PXDBOperation.Update); je.Persist(typeof(PMProjectStatusAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskAllocTotalAccum), PXDBOperation.Insert); je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert); ts.Complete(); } return(batches); }
public override void AutoReleaseCreatedDocuments(PMProject project, BillingResult result, PMRegister reversalDoc) { }