public IEnumerable <FinPeriod> PeriodsBetweenInclusive( PXGraph graph, DateTime startDate, DateTime endDate) { return(FinPeriodIDAttribute.PeriodsBetweenInclusive(graph, startDate, endDate)); }
private void SetDocDateByPeriods(PXCache cache, TaxAdjustment document) { if (document.TaxPeriod == null) { return; } var taxPeriod = ReportTaxProcess.FindTaxPeriodByKey(this, document.VendorID, document.TaxPeriod); if (taxPeriod == null) { return; } DateTime?docDate; if (vendor.Current.TaxReportFinPeriod == true) { var finPeriod = FinPeriodIDAttribute.FindMaxFinPeriodWithEndDataBelongToInterval(this, taxPeriod.StartDate, taxPeriod.EndDate); docDate = finPeriod != null ? finPeriod.FinDate : Accessinfo.BusinessDate; } else { docDate = taxPeriod.EndDateUI; } cache.SetValueExt <TaxAdjustment.docDate>(document, docDate); }
protected override void _(Events.RowUpdated <Invoice> e) { base._(e); if (ShouldUpdateAdjustmentsOnDocumentUpdated(e)) { foreach (Adjust2 adjust in AppliedAdjustments.Select()) { if (!e.Cache.ObjectsEqual <Invoice.branchID>(e.Row, e.OldRow)) { AppliedAdjustments.Cache.SetDefaultExt <Adjust2.adjdBranchID>(adjust); } if (!e.Cache.ObjectsEqual <Invoice.headerTranPeriodID>(e.Row, e.OldRow)) { FinPeriodIDAttribute.DefaultPeriods <Adjust2.adjgFinPeriodID>(AppliedAdjustments.Cache, adjust); FinPeriodIDAttribute.DefaultPeriods <Adjust2.adjdFinPeriodID>(AppliedAdjustments.Cache, adjust); } (AppliedAdjustments.Cache as PXModelExtension <Adjust2>)?.UpdateExtensionMapping(adjust); AppliedAdjustments.Cache.MarkUpdated(adjust); } } }
protected virtual void DRScheduleTran_RecDate_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { DRScheduleTran row = e.Row as DRScheduleTran; if (row != null) { row.FinPeriodID = FinPeriodIDAttribute.PeriodFromDate(this, row.RecDate); } }
protected virtual List <PMTran> CreateExpenseTransactions(PMTask task, out DateTime?lastDate) { lastDate = null; PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus, InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >, InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >, LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >, Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >, And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >, And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this); List <PMTran> trans = new List <PMTran>(); foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID)) { PMProjectStatus ps = (PMProjectStatus)res; InventoryItem item = (InventoryItem)res; PMTran tran = new PMTran(); tran.AccountGroupID = ps.AccountGroupID; tran.ProjectID = ps.ProjectID; tran.TaskID = ps.ProjectTaskID; tran.InventoryID = ps.InventoryID; tran.AccountID = item.InventoryID != null ? item.COGSAcctID : null; tran.SubID = item.InventoryID != null ? item.COGSSubID : null; tran.Amount = ps.Amount; tran.Qty = ps.Qty; tran.UOM = ps.UOM; tran.BAccountID = task.CustomerID; tran.LocationID = task.LocationID; tran.Billable = true; tran.UseBillableQty = true; tran.BillableQty = ps.RevisedQty; tran.Date = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID); tran.StartDate = tran.Date; tran.EndDate = tran.Date; tran.FinPeriodID = ps.PeriodID; tran.TranPeriodID = ps.PeriodID; tran.Released = true; if (lastDate != null) { if (lastDate < tran.Date) { lastDate = tran.Date; } } else { lastDate = tran.Date; } trans.Add(Transactions.Insert(tran)); } return(trans); }
private Dictionary <string, string> CreateReportParams() { var branch = _gafRepository.GetBranchByID(GAFPeriodView.Current.BranchID); var taxAgency = _gafRepository.GetVendorsByIDs(GAFPeriodView.Current.TaxAgencyID.SingleToArray()).Single(); var taxPeriod = _gafRepository.GetTaxPeriodByKey(branch.ParentBranchID, taxAgency.BAccountID, GAFPeriodView.Current.TaxPeriodID); return(new Dictionary <string, string> { ["MasterBranchID"] = branch.BranchCD, ["VendorID"] = taxAgency.AcctCD, ["TaxPeriodID"] = FinPeriodIDAttribute.FormatForDisplay(taxPeriod.TaxPeriodID) }); }
protected virtual void FATran_FinPeriodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { FATran tran = (FATran)e.Row; if (tran?.AssetID == null || tran.BookID == null || tran.TranDate == null) { return; } try { // TODO: AC-106141 // Use BranchID of the fixed asset referenced by local FATran FABookPeriod period = PXSelect < FABookPeriod, Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >, And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > .Select(this, tran.BookID, (string)e.NewValue); if (period == null) { throw new PXSetPropertyException(Messages.NoPeriodsDefined); } FABookBalance bal = bookbalances.SelectSingle(tran.AssetID, tran.BookID); if ((tran.TranType == FATran.tranType.DepreciationPlus || tran.TranType == FATran.tranType.DepreciationMinus) && tran.Origin == FARegister.origin.Adjustment) { if (!string.IsNullOrEmpty(bal.CurrDeprPeriod) && string.CompareOrdinal((string)e.NewValue, bal.CurrDeprPeriod) >= 0) { throw new PXSetPropertyException(CS.Messages.Entry_LT, FinPeriodIDFormattingAttribute.FormatForError(bal.CurrDeprPeriod)); } if (!string.IsNullOrEmpty(bal.LastDeprPeriod) && string.CompareOrdinal((string)e.NewValue, bal.LastDeprPeriod) > 0) { throw new PXSetPropertyException(CS.Messages.Entry_LE, FinPeriodIDFormattingAttribute.FormatForError(bal.LastDeprPeriod)); } if (!string.IsNullOrEmpty(bal.DeprFromPeriod) && string.CompareOrdinal((string)e.NewValue, bal.DeprFromPeriod) < 0) { throw new PXSetPropertyException(CS.Messages.Entry_GE, FinPeriodIDFormattingAttribute.FormatForError(bal.DeprFromPeriod)); } } } catch (PXSetPropertyException) { e.NewValue = FinPeriodIDAttribute.FormatForDisplay((string)e.NewValue); throw; } }
private static void _createPayments(List <ARInvoice> list, PayBillsFilter filter, CurrencyInfo info) { bool failed = false; ARPaymentEntry pe = PXGraph.CreateInstance <ARPaymentEntry>(); list.Sort((in1, in2) => { if (in1.CustomerID != in2.CustomerID) { return(((IComparable)in1.CustomerID).CompareTo(in2.CustomerID)); } return(((IComparable)in1.PMInstanceID).CompareTo(in2.PMInstanceID)); } ); for (int i = 0; i < list.Count; i++) { ARInvoice doc = list[i]; ARPayment pmt = null; bool docFailed = false; try { pe.CreatePayment(doc, info, filter.PayDate, filter.PayFinPeriodID, false); pmt = pe.Document.Current; if (pmt != null) { pmt.Hold = false; FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.finPeriodID>(pe.Document.Cache, pmt, filter.PayFinPeriodID); } pe.Save.Press(); } catch (Exception e) { PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetError(i, e.Message); docFailed = failed = true; } if (!docFailed) { PXFilteredProcessing <ARInvoice, PayBillsFilter> .SetInfo(i, PXMessages.LocalizeFormatNoPrefixNLA(Messages.ARPaymentIsCreatedProcessingINProgress, pmt.RefNbr)); } } if (failed) { throw new PXException(Messages.CreationOfARPaymentFailedForSomeInvoices); } }
/// <summary> /// Retrieves the first financial period of the year corresponding /// to the financial period specified. /// If no such period exists, returns <c>null</c>. /// </summary> public string GetFirstPeriodOfYear(string financialPeriodID) { if (financialPeriodID == null) { return(null); } PXGraph graph = PXGraph.CreateInstance <FiscalPeriodMaint>(); string firstPeriodOfYear = FinPeriodIDAttribute.GetFirstFinPeriodIDOfYear(financialPeriodID); if (!FinPeriodIDAttribute.PeriodExists(graph, financialPeriodID)) { return(null); } return(FinPeriodIDFormattingAttribute.FormatForDisplay(firstPeriodOfYear)); }
/// <summary> /// Query to get data for calculation of the begin balances of accounts. /// </summary> /// <returns>Account; /// GLHistory: total of ptdDebit and ptdCredit of specified period; /// AH: total of finYtdBalance for last period activity period.</returns> public IEnumerable <PXResult <Account, GLHistory, AH> > GetAccountsWithDataToCalcBeginBalancesExcludingYTDNetIncAcc(int?branchID, int?ledgerID, string finPeriodID) { var glSetup = GetGLSetup(); var childBranchIds = PXAccess.GetChildBranchIDs(GetBranchByID(branchID).BranchCD); return(PXSelectJoinGroupBy <Account, LeftJoin <GLHistoryByPeriod, On <GLHistoryByPeriod.branchID, In <Required <GLHistoryByPeriod.branchID> >, And <GLHistoryByPeriod.ledgerID, Equal <Required <GLHistoryByPeriod.ledgerID> >, And <Account.accountID, Equal <GLHistoryByPeriod.accountID>, And <GLHistoryByPeriod.finPeriodID, Equal <Required <GLHistoryByPeriod.finPeriodID> >, And <Where2 <Where <Account.type, Equal <AccountType.asset>, Or <Account.type, Equal <AccountType.liability> > >, Or <Where <GLHistoryByPeriod.lastActivityPeriod, GreaterEqual <Required <GLHistoryByPeriod.lastActivityPeriod> >, // greater than the first period of a year And <Where <Account.type, Equal <AccountType.expense>, Or <Account.type, Equal <AccountType.income> > > > > > > > > > > >, //to get saldo in selected period LeftJoin <GLHistory, On <GLHistoryByPeriod.branchID, Equal <GLHistory.branchID>, And <GLHistoryByPeriod.ledgerID, Equal <GLHistory.ledgerID>, And <GLHistoryByPeriod.accountID, Equal <GLHistory.accountID>, And <GLHistoryByPeriod.subID, Equal <GLHistory.subID>, And <GLHistoryByPeriod.finPeriodID, Equal <GLHistory.finPeriodID> > > > > >, //to get ending balance for last activity period LeftJoin <AH, On <GLHistoryByPeriod.ledgerID, Equal <AH.ledgerID>, And <GLHistoryByPeriod.branchID, Equal <AH.branchID>, And <GLHistoryByPeriod.accountID, Equal <AH.accountID>, And <GLHistoryByPeriod.subID, Equal <AH.subID>, And <GLHistoryByPeriod.lastActivityPeriod, Equal <AH.finPeriodID> > > > > > > > >, Where <Account.accountID, NotEqual <Required <Account.accountID> > >, // not YTD Net Income Account>, Aggregate < Sum <AH.finYtdBalance, Sum <GLHistory.finPtdCredit, Sum <GLHistory.finPtdDebit, GroupBy <Account.accountID> > > > > > .Select(_graph, childBranchIds, ledgerID, finPeriodID, FinPeriodIDAttribute.GetFirstFinPeriodIDOfYear(finPeriodID), glSetup.YtdNetIncAccountID) .Cast <PXResult <Account, GLHistoryByPeriod, GLHistory, AH> >() .Select(row => new PXResult <Account, GLHistory, AH>((Account)row, (GLHistory)row, (AH)row))); }
public virtual void CopyPeriods <TDAC, TFinPeriodID, TMasterFinPeriodID>(PXCache cache, TDAC src, TDAC dest) where TDAC : class, IBqlTable, new() where TFinPeriodID : class, IBqlField where TMasterFinPeriodID : class, IBqlField { if (!cache.ObjectsEqual <TFinPeriodID, TMasterFinPeriodID>(src, dest)) { object origFinPeriodID = cache.GetValue <TFinPeriodID>(src); string tranPeriodID = (string)cache.GetValue <TMasterFinPeriodID>(src); try { FinPeriodIDAttribute.SetPeriodsByMaster <TFinPeriodID>(cache, dest, tranPeriodID); origFinPeriodID = cache.GetValue <TFinPeriodID>(dest); cache.RaiseFieldVerifying <TFinPeriodID>(dest, ref origFinPeriodID); } catch (PXException e) { cache.RaiseExceptionHandling <TFinPeriodID>(dest, origFinPeriodID, e); } } }
protected virtual void _(Events.RowUpdated <Payment> e) { if (!e.Cache.ObjectsEqual <Payment.adjDate, Payment.adjTranPeriodID, Payment.curyID, Payment.branchID>(e.Row, e.OldRow)) { foreach (Adjust adjust in Adjustments.Select()) { if (!e.Cache.ObjectsEqual <Payment.branchID>(e.Row, e.OldRow)) { Adjustments.Cache.SetDefaultExt <Adjust.adjgBranchID>(adjust); } if (!e.Cache.ObjectsEqual <Payment.adjTranPeriodID>(e.Row, e.OldRow)) { FinPeriodIDAttribute.DefaultPeriods <Adjust.adjgFinPeriodID>(Adjustments.Cache, adjust); } (Adjustments.Cache as PXModelExtension <Adjust>)?.UpdateExtensionMapping(adjust); Adjustments.Cache.MarkUpdated(adjust); } } }
/// <summary> /// Retrieves the financial period with the same <see cref="FinPeriod.PeriodNbr"/> /// as the one specified, but residing in the previous financial year. /// If no such period exists, returns <c>null</c>. /// </summary> public string GetSamePeriodInPreviousYear(string financialPeriodID) { if (financialPeriodID == null) { return(null); } PXGraph graph = PXGraph.CreateInstance <FiscalPeriodMaint>(); try { string resultingPeriodID = FinPeriodIDAttribute.GetSamePeriodInPreviousYear( graph, financialPeriodID); return(FinPeriodIDFormattingAttribute.FormatForDisplay(resultingPeriodID)); } catch (PXFinPeriodException) { return(null); } }
protected virtual void RunAutoBudget(PMTask task) { PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus, InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >, InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >, LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >, Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >, And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >, And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this); List <PMTran> trans = new List <PMTran>(); foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID)) { PMProjectStatus ps = (PMProjectStatus)res; InventoryItem item = (InventoryItem)res; PMTran tran = new PMTran(); tran.AccountGroupID = ps.AccountGroupID; tran.ProjectID = ps.ProjectID; tran.TaskID = ps.ProjectTaskID; tran.InventoryID = ps.InventoryID; tran.AccountID = item.InventoryID != null ? item.SalesAcctID : null; tran.Amount = ps.RevisedAmount; tran.Qty = ps.RevisedQty; tran.UOM = ps.UOM; tran.BAccountID = task.CustomerID; tran.LocationID = task.LocationID; tran.Billable = true; tran.BillableQty = ps.RevisedQty; tran.Date = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID); tran.StartDate = tran.Date; tran.EndDate = tran.Date; tran.FinPeriodID = ps.PeriodID; tran.TranPeriodID = ps.PeriodID; trans.Add(tran); } }
private void ValidateDocDate(PXCache cache, TaxAdjustment doc) { if (doc.DocDate == null || doc.TaxPeriod == null || doc.BranchID == null) { return; } var taxPeriod = TaxYearMaint.FindTaxPeriodByKey(this, PXAccess.GetMasterBranchID(doc.BranchID).First(), doc.VendorID, doc.TaxPeriod); if (taxPeriod == null) { return; } string errorMessage = null; if (vendor.Current.TaxReportFinPeriod == true) { var finPeriod = FinPeriodIDAttribute.GetByID(this, doc.FinPeriodID); if (finPeriod.FinDate >= taxPeriod.EndDate) { errorMessage = Messages.SelectedDateBelongsToTheTaxPeriodThatIsGreaterThanTheSpecifiedOne; } } else if (doc.DocDate >= taxPeriod.EndDate) { errorMessage = Messages.SelectedDateBelongsToTheTaxPeriodThatIsGreaterThanTheSpecifiedOne; } var ex = errorMessage != null ? new PXSetPropertyException(errorMessage, PXErrorLevel.Warning) : null; cache.RaiseExceptionHandling <TaxAdjustment.docDate>(doc, doc.DocDate, ex); }
protected virtual void ARRetainageFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { ARRetainageFilter filter = e.Row as ARRetainageFilter; if (filter == null) { return; } bool isAutoRelease = ARSetup.Current.RetainageInvoicesAutoRelease == true; DocumentList.SetProcessDelegate(delegate(List <ARInvoiceExt> list) { ARInvoiceEntry graph = CreateInstance <ARInvoiceEntry>(); ARInvoiceEntryRetainage retainageExt = graph.GetExtension <ARInvoiceEntryRetainage>(); RetainageOptions retainageOptions = new RetainageOptions(); retainageOptions.DocDate = filter.DocDate; retainageOptions.MasterFinPeriodID = FinPeriodIDAttribute.CalcMasterPeriodID <ARRetainageFilter.finPeriodID>(graph.Caches[typeof(ARRetainageFilter)], filter); retainageExt.ReleaseRetainageProc(list, retainageOptions, isAutoRelease); }); }
private static string GetMessage(string financialPeriodId, int offset) { if (string.IsNullOrEmpty(financialPeriodId)) { return(Messages.NoPeriodsDefined); } else { switch (offset) { case 0: return(PXLocalizer.LocalizeFormat(Messages.NoFinancialPeriodWithId, FinPeriodIDAttribute.FormatForError(financialPeriodId))); case -1: return(PXLocalizer.LocalizeFormat(Messages.NoFinancialPeriodBefore, FinPeriodIDAttribute.FormatForError(financialPeriodId))); case 1: return(PXLocalizer.LocalizeFormat(Messages.NoFinancialPeriodAfter, FinPeriodIDAttribute.FormatForError(financialPeriodId))); default: return(PXLocalizer.LocalizeFormat(Messages.NoFinancialPeriodForOffset, Math.Abs(offset), offset > 0 ? Messages.AfterLowercase : Messages.BeforeLowercase, FinPeriodIDAttribute.FormatForError(financialPeriodId))); } } }
protected virtual IEnumerable items() { ScheduleRecognitionFilter filter = Filter.Current; if (filter == null) { yield break; } bool found = false; foreach (ScheduledTran item in Items.Cache.Inserted) { found = true; yield return(item); } if (found) { yield break; } PXSelectBase <DRScheduleTran> select = new PXSelectJoin <DRScheduleTran, InnerJoin <DRScheduleDetail, On <DRScheduleTran.scheduleID, Equal <DRScheduleDetail.scheduleID>, And <DRScheduleTran.componentID, Equal <DRScheduleDetail.componentID> > >, LeftJoin <InventoryItem, On <DRScheduleTran.componentID, Equal <InventoryItem.inventoryID> > > >, Where <DRScheduleTran.recDate, LessEqual <Current <ScheduleRecognitionFilter.recDate> >, And <DRScheduleTran.status, Equal <DRScheduleTranStatus.OpenStatus>, And <DRScheduleDetail.status, NotEqual <DRScheduleStatus.DraftStatus> > > >, OrderBy <Asc <DRScheduleTran.scheduleID, Asc <DRScheduleTran.componentID, Asc <DRScheduleTran.recDate, Asc <DRScheduleTran.lineNbr> > > > > >(this); if (!string.IsNullOrEmpty(filter.DeferredCode)) { select.WhereAnd <Where <DRScheduleDetail.defCode, Equal <Current <ScheduleRecognitionFilter.deferredCode> > > >(); } Dictionary <string, string> added = new Dictionary <string, string>(); foreach (PXResult <DRScheduleTran, DRScheduleDetail, InventoryItem> resultSet in select.Select()) { DRScheduleTran tran = (DRScheduleTran)resultSet; DRScheduleDetail schedule = (DRScheduleDetail)resultSet; InventoryItem item = (InventoryItem)resultSet; string key = string.Format("{0}.{1}", tran.ScheduleID, tran.ComponentID); bool doInsert = false; if (added.ContainsKey(key)) { string addedFinPeriod = added[key]; if (tran.FinPeriodID == addedFinPeriod) { doInsert = true; } } else { doInsert = true; added.Add(key, tran.FinPeriodID); } if (doInsert) { ScheduledTran result = new ScheduledTran(); result.BranchID = tran.BranchID; result.AccountID = tran.AccountID; result.Amount = tran.Amount; result.ComponentID = tran.ComponentID; result.DefCode = schedule.DefCode; result.FinPeriodID = tran.FinPeriodID; result.LineNbr = tran.LineNbr; result.Module = tran.Module; result.RecDate = tran.RecDate; result.ScheduleID = tran.ScheduleID; result.SubID = tran.SubID; result.ComponentCD = item.InventoryCD; result.DocType = DRScheduleDocumentType.BuildDocumentType(schedule.Module, schedule.DocType); Items.Cache.SetStatus(result, PXEntryStatus.Inserted); yield return(result); // Items.Insert(result); } } //Virtual Records (CashReceipt): PXSelectBase <ARInvoice> s = null; if (!string.IsNullOrEmpty(filter.DeferredCode)) { s = new PXSelectJoinGroupBy <ARInvoice, InnerJoin <ARTran, On <ARTran.tranType, Equal <ARInvoice.docType>, And <ARTran.refNbr, Equal <ARInvoice.refNbr> > >, InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>, And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt>, And <DRDeferredCode.deferredCodeID, Equal <Current <ScheduleRecognitionFilter.deferredCode> > > > >, InnerJoin <DRSchedule, On <ARTran.tranType, Equal <DRSchedule.docType>, And <ARTran.refNbr, Equal <DRSchedule.refNbr>, And <ARTran.lineNbr, Equal <DRSchedule.lineNbr> > > >, InnerJoin <DRScheduleDetail, On <DRSchedule.scheduleID, Equal <DRScheduleDetail.scheduleID> > > > > >, Where <ARInvoice.released, Equal <boolTrue>, And <DRScheduleDetail.isOpen, Equal <boolTrue> > >, Aggregate <GroupBy <ARInvoice.docType, GroupBy <ARInvoice.refNbr> > > >(this); } else { s = new PXSelectJoinGroupBy <ARInvoice, InnerJoin <ARTran, On <ARTran.tranType, Equal <ARInvoice.docType>, And <ARTran.refNbr, Equal <ARInvoice.refNbr> > >, InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>, And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt> > >, InnerJoin <DRSchedule, On <ARTran.tranType, Equal <DRSchedule.docType>, And <ARTran.refNbr, Equal <DRSchedule.refNbr>, And <ARTran.lineNbr, Equal <DRSchedule.lineNbr> > > >, InnerJoin <DRScheduleDetail, On <DRSchedule.scheduleID, Equal <DRScheduleDetail.scheduleID> > > > > >, Where <ARInvoice.released, Equal <boolTrue>, And <DRScheduleDetail.isOpen, Equal <boolTrue> > >, Aggregate <GroupBy <ARInvoice.docType, GroupBy <ARInvoice.refNbr> > > >(this); } foreach (ARInvoice inv in s.Select()) { PXSelectBase <ARTran> trs = new PXSelectJoin <ARTran, InnerJoin <DRDeferredCode, On <ARTran.deferredCode, Equal <DRDeferredCode.deferredCodeID>, And <DRDeferredCode.method, Equal <DeferredMethodType.cashReceipt> > > >, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > >(this); foreach (PXResult <ARTran, DRDeferredCode> res in trs.Select(inv.DocType, inv.RefNbr)) { List <ScheduledTran> virtualRecords = new List <ScheduledTran>(); List <ScheduledTran> virtualVoidedRecords = new List <ScheduledTran>(); ARTran tr = (ARTran)res; DRDeferredCode dc = (DRDeferredCode)res; decimal trPart = 0; if (inv.LineTotal.Value != 0) { trPart = tr.TranAmt.Value / inv.LineTotal.Value; } InventoryItem invItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, tr.InventoryID); //NOTE: Multiple Components are not supported in CashReceipt Deferred Revenue Recognition. DRSchedule schedule = GetScheduleByFID(inv.DocType, inv.RefNbr, tr.LineNbr); DRScheduleDetail scheduleDetail = GetScheduleDetailbyID(schedule.ScheduleID, tr.InventoryID != null ? tr.InventoryID : DRScheduleDetail.EmptyComponentID); int lineNbr = scheduleDetail.LineCntr ?? 0; PXSelectBase <ARAdjust> ads = new PXSelectJoin <ARAdjust, LeftJoin <DRScheduleTran, On <ARAdjust.adjgDocType, Equal <DRScheduleTran.adjgDocType>, And <ARAdjust.adjgRefNbr, Equal <DRScheduleTran.adjgRefNbr> > > >, Where <ARAdjust.adjdDocType, Equal <Required <ARAdjust.adjdDocType> >, And <ARAdjust.adjdRefNbr, Equal <Required <ARAdjust.adjdRefNbr> >, And <DRScheduleTran.scheduleID, IsNull, And <ARAdjust.adjgDocType, NotEqual <ARDocType.creditMemo> > > > >, OrderBy <Asc <ARAdjust.adjgDocDate> > >(this); foreach (ARAdjust ad in ads.Select(inv.DocType, inv.RefNbr)) { lineNbr++; decimal amtRaw = trPart * ad.AdjAmt.Value; decimal amt = PXDBCurrencyAttribute.BaseRound(this, amtRaw); ScheduledTran result = new ScheduledTran(); result.BranchID = ad.AdjgBranchID; result.Amount = amt; result.ComponentID = tr.InventoryID; result.DefCode = tr.DeferredCode; result.FinPeriodID = FinPeriodIDAttribute.PeriodFromDate(this, ad.AdjgDocDate); result.LineNbr = lineNbr; result.Module = schedule.Module; result.RecDate = ad.AdjgDocDate; result.ScheduleID = schedule.ScheduleID; result.DocType = schedule.DocType; result.AdjgDocType = ad.AdjgDocType; result.AdjgRefNbr = ad.AdjgRefNbr; result.AdjNbr = ad.AdjNbr; result.IsVirtual = true; result.AccountID = scheduleDetail.AccountID; result.SubID = scheduleDetail.SubID; result.ComponentCD = invItem == null ? "" : invItem.InventoryCD; if (ad.Voided == true) { if (ad.AdjgDocType == ARDocType.VoidPayment && virtualVoidedRecords.Count > 0) { ScheduledTran tran = virtualVoidedRecords.Where <ScheduledTran>(v => (v.AdjgDocType == ARDocType.Payment && v.AdjgRefNbr == ad.AdjgRefNbr && v.AdjNbr == ad.AdjNbr)).First <ScheduledTran>(); if (tran != null) { virtualVoidedRecords.Remove(tran); } } else { virtualVoidedRecords.Add(result); } } else { virtualRecords.Add(result); } } foreach (ScheduledTran v in virtualRecords) { Items.Cache.SetStatus(v, PXEntryStatus.Inserted); yield return(v); // Items.Insert(v); } foreach (ScheduledTran v in virtualVoidedRecords) { Items.Cache.SetStatus(v, PXEntryStatus.Inserted); yield return(v); // Items.Insert(v); } } } Items.Cache.IsDirty = false; }
private Batch BuildReclassificationBatch(IReadOnlyCollection <ReclassificationItem> transForReclassItems, List <GLTran> transMovedFromExistingBatch, Batch batchForEditing = null) { DateTime earliestNewTranDate = DateTime.MaxValue; Batch batch; var representativeTranForReclass = transForReclassItems.First().HeadTranForReclass; JournalEntryInstance.BatchModule.Current = null; if (batchForEditing == null) { batch = JournalEntryInstance.BatchModule.Insert(new Batch() { BranchID = representativeTranForReclass.NewBranchID, FinPeriodID = representativeTranForReclass.NewFinPeriodID }); } else { batch = batchForEditing; JournalEntryInstance.BatchModule.Current = batch; } //adding or editing of transactions foreach (var reclassItem in transForReclassItems) { IEnumerable <GLTranForReclassification> headTranForReclass = IsReclassAttrChanged(reclassItem.HeadTranForReclass) ? reclassItem.HeadTranForReclass.SingleToArray().Union(reclassItem.SplittingTransForReclass) : new GLTranForReclassification[0]; IEnumerable <GLTranForReclassification> tranForReclassToProcess = headTranForReclass.Union(reclassItem.SplittingTransForReclass); foreach (var tranForReclass in tranForReclassToProcess) { GLTran reclassifyingTran = CreateOrEditReclassTranPair(tranForReclass, reclassItem, transMovedFromExistingBatch); if (reclassifyingTran.TranDate < earliestNewTranDate) { earliestNewTranDate = reclassifyingTran.TranDate.Value; } } } //remove deleted trans if (batchForEditing != null) { foreach (var tranForReclassToDel in State.GLTranForReclassToDelete) { var reverseTran = LocateReverseTran(JournalEntryInstance.GLTranModuleBatNbr.Cache, tranForReclassToDel); var reclassifyingTran = LocateReclassifyingTran(JournalEntryInstance.GLTranModuleBatNbr.Cache, tranForReclassToDel); JournalEntryInstance.GLTranModuleBatNbr.Delete(reclassifyingTran); JournalEntryInstance.GLTranModuleBatNbr.Delete(reverseTran); } } //creating and editing of batch header if (batchForEditing == null) { var batchCuryInfo = PXCache <CurrencyInfo> .CreateCopy(transForReclassItems.First().CuryInfo); batchCuryInfo.CuryInfoID = null; batchCuryInfo = JournalEntryInstance.currencyinfo.Insert(batchCuryInfo); batch.BatchType = BatchTypeCode.Reclassification; batch.BranchID = representativeTranForReclass.NewBranchID; FinPeriodIDAttribute.SetPeriodsByMaster <Batch.finPeriodID>(JournalEntryInstance.BatchModule.Cache, batch, representativeTranForReclass.TranPeriodID); batch.LedgerID = representativeTranForReclass.LedgerID; batch.Module = BatchModule.GL; batch.CuryInfoID = batchCuryInfo.CuryInfoID; } else { CurrencyInfo firstCuryInfo = null; int? minLineNbr = int.MaxValue; foreach (var item in transForReclassItems) { var reclassTran = item.ReclassifyingTrans.GetItemWithMin(m => m.LineNbr.Value); if (minLineNbr > reclassTran.LineNbr) { minLineNbr = reclassTran.LineNbr; firstCuryInfo = item.CuryInfo; } } var batchCuryInfo = PXCache <CurrencyInfo> .CreateCopy(firstCuryInfo); batchCuryInfo.CuryInfoID = JournalEntryInstance.currencyInfo.CuryInfoID; batchCuryInfo.tstamp = JournalEntryInstance.currencyInfo.tstamp; JournalEntryInstance.currencyinfo.Update(batchCuryInfo); } batch.DateEntered = earliestNewTranDate; batch.CuryID = representativeTranForReclass.CuryID; if (State.ReclassScreenMode == ReclassScreenMode.Reversing) { batch.OrigModule = State.OrigBatchModuleToReverse; batch.OrigBatchNbr = State.OrigBatchNbrToReverse; batch.AutoReverseCopy = true; } batch = JournalEntryInstance.BatchModule.Update(batch); return(batch); }
public FinPeriod FindLastYearNotAdjustmentPeriod(string finYear) { return(FinPeriodIDAttribute.FindLastYearNotAdjustmentPeriod(_graph, finYear)); }
public IEnumerable <FinPeriod> GetAdjustmentFinPeriods(string year) { return(FinPeriodIDAttribute.GetAdjustmentFinPeriods(_graph, year)); }
public IEnumerable <FinPeriod> GetFinPeriodsInInterval(DateTime?fromDate, DateTime?tillDate) { return(FinPeriodIDAttribute.GetFinPeriodsInInterval(_graph, fromDate, tillDate)); }
public static void SetPeriodsByMaster(PXCache docCache, CATran caTran, string masterPeriodID) { FinPeriodIDAttribute.SetPeriodsByMaster <CATran.finPeriodID>(docCache.Graph.Caches[typeof(CATran)], caTran, masterPeriodID); }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.inventoryID>(ResultRecords.Cache, null, false); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.finPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.tranPerNbr>(ResultRecords.Cache, null, false); //??? PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.subItemID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible<InventoryTranHistEnqResult.lotSerialNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay); var resultList = new List<PXResult<InventoryTranHistEnqResult, INTran>>(); if (filter.InventoryID == null) { return resultList; //empty } PXSelectBase<INTranSplit> cmd = new PXSelectReadonly2<INTranSplit, InnerJoin<INTran, On<INTran.docType, Equal<INTranSplit.docType>, And<INTran.refNbr, Equal<INTranSplit.refNbr>, And<INTran.lineNbr, Equal<INTranSplit.lineNbr>>>>, InnerJoin<INSubItem, On<INSubItem.subItemID, Equal<INTranSplit.subItemID>>, InnerJoin<INSite, On<INSite.siteID, Equal<INTran.siteID>>>>>, Where<INTranSplit.inventoryID, Equal<Current<InventoryTranHistEnqFilter.inventoryID>>, And<Match<INSite, Current<AccessInfo.userName>>>>, OrderBy<Asc<INTranSplit.docType, Asc<INTranSplit.refNbr, Asc<INTranSplit.lineNbr, Asc<INTranSplit.splitLineNbr>>>>>>(this); PXSelectBase<INItemSiteHistByPeriod> cmdBegBalance = new PXSelectReadonly2<INItemSiteHistByPeriod, InnerJoin<INItemSiteHist, On<INItemSiteHist.inventoryID, Equal<INItemSiteHistByPeriod.inventoryID>, And<INItemSiteHist.siteID, Equal<INItemSiteHistByPeriod.siteID>, And<INItemSiteHist.subItemID, Equal<INItemSiteHistByPeriod.subItemID>, And<INItemSiteHist.locationID, Equal<INItemSiteHistByPeriod.locationID>, And<INItemSiteHist.finPeriodID, Equal<INItemSiteHistByPeriod.lastActivityPeriod>>>>>>, InnerJoin<INSubItem, On<INSubItem.subItemID, Equal<INItemSiteHistByPeriod.subItemID>>, InnerJoin<INSite, On<INSite.siteID, Equal<INItemSiteHistByPeriod.siteID>>>>>, Where<INItemSiteHistByPeriod.inventoryID, Equal<Current<InventoryTranHistEnqFilter.inventoryID>>, And<INItemSiteHistByPeriod.finPeriodID, Equal<Required<INItemSiteHistByPeriod.finPeriodID>>, And<Match<INSite, Current<AccessInfo.userName>>>>>>(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled<FeaturesSet.subItem>()) { cmdBegBalance.WhereAnd<Where<INSubItem.subItemCD, Like<Current<InventoryTranHistEnqFilter.subItemCDWildcard>>>>(); cmd.WhereAnd<Where<INSubItem.subItemCD, Like<Current<InventoryTranHistEnqFilter.subItemCDWildcard>>>>(); } if (filter.SiteID != null && PXAccess.FeatureInstalled<FeaturesSet.warehouse>()) { cmdBegBalance.WhereAnd<Where<INItemSiteHistByPeriod.siteID, Equal<Current<InventoryTranHistEnqFilter.siteID>>>>(); cmd.WhereAnd<Where<INTranSplit.siteID, Equal<Current<InventoryTranHistEnqFilter.siteID>>>>(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled<FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmdBegBalance.WhereAnd<Where<INItemSiteHistByPeriod.locationID, Equal<Current<InventoryTranHistEnqFilter.locationID>>>>(); cmd.WhereAnd<Where<INTranSplit.locationID, Equal<Current<InventoryTranHistEnqFilter.locationID>>>>(); } if ((filter.LotSerialNbr ?? "") != "" && PXAccess.FeatureInstalled<FeaturesSet.lotSerialTracking>()) { cmd.WhereAnd<Where<INTranSplit.lotSerialNbr, Like<Current<InventoryTranHistEnqFilter.lotSerialNbrWildcard>>>>(); } if (!includeUnreleased) { cmd.WhereAnd<Where<INTranSplit.released, Equal<True>>>(); } decimal cumulativeQty = 0m; string TranPeriodID; DateTime? PeriodStartDate; bool AnyPeriod = false; try { TranPeriodID = FinPeriodIDAttribute.PeriodFromDate(this, filter.StartDate); PeriodStartDate = FinPeriodIDAttribute.PeriodStartDate(this, TranPeriodID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } int startRow = 0; int totalRows = 0; int maximumRows = 0; if (includeUnreleased) { FinPeriod firstOpenOrCurrentClosedPeriod = PXSelectReadonly<FinPeriod, Where<FinPeriod.finPeriodID, LessEqual<Required<FinPeriod.finPeriodID>>, And<FinPeriod.iNClosed, Equal<False>, Or<FinPeriod.finPeriodID, Equal<Required<FinPeriod.finPeriodID>>>>>, OrderBy<Asc<FinPeriod.finPeriodID>>>.SelectWindowed(this, 0, 1, TranPeriodID, TranPeriodID); if (firstOpenOrCurrentClosedPeriod != null ) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodIDAttribute.PeriodStartDate(this, firstOpenOrCurrentClosedPeriod.FinPeriodID); } foreach (PXResult<INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd<Where<INTranSplit.tranDate, GreaterEqual<Required<INTranSplit.tranDate>>>>() .WhereAnd<Where<INTranSplit.tranDate, Less<Required<INTranSplit.tranDate>>>>() .AggregateNew<Aggregate<GroupBy<INTranSplit.inventoryID, GroupBy<INTranSplit.invtMult, Sum<INTranSplit.baseQty>>>>>()); foreach (PXResult<INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd<Where<INTranSplit.tranDate, Less<Required<INTranSplit.tranDate>>>>() .AggregateNew<Aggregate<GroupBy<INTranSplit.inventoryID, GroupBy<INTranSplit.invtMult, Sum<INTranSplit.baseQty>>>>>()); foreach (PXResult<INTranSplit> res in v2.Select(new object[0], new object[] { filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } else { foreach (PXResult<INItemSiteHistByPeriod, INItemSiteHist> res in cmdBegBalance.Select(TranPeriodID)) { INItemSiteHistByPeriod byperiod = res; INItemSiteHist hist = res; cumulativeQty += string.Equals(byperiod.FinPeriodID, byperiod.LastActivityPeriod) ? (decimal)hist.TranBegQty : (decimal)hist.TranYtdQty; AnyPeriod = true; } if (AnyPeriod) { //if StartDate is not on the Period border, make additional select with grouping if (PeriodStartDate != filter.StartDate) { PXView v2 = new PXView(this, true, cmd.View.BqlSelect .WhereAnd<Where<INTranSplit.tranDate, GreaterEqual<Required<INTranSplit.tranDate>>>>() .WhereAnd<Where<INTranSplit.tranDate, Less<Required<INTranSplit.tranDate>>>>() .AggregateNew<Aggregate<GroupBy<INTranSplit.inventoryID, GroupBy<INTranSplit.invtMult, Sum<INTranSplit.baseQty>>>>>()); foreach (PXResult<INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref startRow, 0, ref totalRows)) { INTranSplit ts_rec = res; cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } } if (filter.StartDate != null) { cmd.WhereAnd<Where<INTranSplit.tranDate, GreaterEqual<Current<InventoryTranHistEnqFilter.startDate>>>>(); } if (filter.EndDate != null) { cmd.WhereAnd<Where<INTranSplit.tranDate, LessEqual<Current<InventoryTranHistEnqFilter.endDate>>>>(); } string[] newSortColumns; bool[] newDescendings; AlterSorts(out newSortColumns, out newDescendings); PXFilterRow[] newFilters = AlterFilters(); //if user clicks last, sorts will be inverted //as it is not possible to calculate beginning balance from the end //we will select without top from the start and then apply reverse order and select top n records //for next page we will ommit startrow to set beginning balance correctly //top (n, m) will be set in the outer search results since we do not reset PXView.StartRow to 0 startRow = 0; maximumRows = !PXView.ReverseOrder ? PXView.StartRow + PXView.MaximumRows : 0; totalRows = 0; PXView selectView = !summaryByDay ? cmd.View : new PXView(this, true, cmd.View.BqlSelect.AggregateNew<Aggregate<GroupBy<INTranSplit.tranDate, Sum<INTranSplit.qtyIn, Sum<INTranSplit.qtyOut>>>>>()); List<object> intermediateResult = selectView.Select(PXView.Currents, new object[] { filter.StartDate }, new string[newSortColumns.Length], newSortColumns, PXView.Descendings, newFilters, ref startRow, maximumRows, ref totalRows); int gridLineNbr = 0; foreach (PXResult<INTranSplit, INTran, INSubItem> it in intermediateResult) { INTranSplit ts_rec = (INTranSplit)it; INTran t_rec = (INTran)it; if (ts_rec.TranDate < filter.StartDate) { cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } else { if (summaryByDay) { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult<InventoryTranHistEnqResult, INTran>(item, null)); cumulativeQty += (ts_rec.QtyIn - ts_rec.QtyOut) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; item.QtyIn = ts_rec.QtyIn; item.QtyOut = ts_rec.QtyOut; item.EndQty = item.BegQty + ts_rec.QtyIn - ts_rec.QtyOut; item.InventoryID = ts_rec.InventoryID; item.TranType = ts_rec.TranType; item.DocType = ts_rec.DocType; item.DocRefNbr = ts_rec.RefNbr; item.SubItemID = ts_rec.SubItemID; item.SiteID = ts_rec.SiteID; item.LocationID = ts_rec.LocationID; item.LotSerialNbr = ts_rec.LotSerialNbr; item.FinPerNbr = t_rec.FinPeriodID; item.TranPerNbr = t_rec.TranPeriodID; item.Released = t_rec.Released; item.GridLineNbr = ++gridLineNbr; decimal? unitcost; if(filter.ShowAdjUnitCost ?? false) { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? (ts_rec.TotalCost + ts_rec.AdditionalCost) / ts_rec.TotalQty : 0m; } else { unitcost = ts_rec.TotalQty != null && ts_rec.TotalQty != 0m ? ts_rec.TotalCost / ts_rec.TotalQty : 0m; } item.UnitCost = unitcost; resultList.Add(new PXResult<InventoryTranHistEnqResult, INTran>(item, t_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } if (!PXView.ReverseOrder) return resultList; return PXView.Sort(resultList); }
public virtual IEnumerable amts(PXAdapter adapter) { AccBalanceByAssetFilter filter = Filter.Current; if (filter == null) { yield break; } PXSelectBase <FATran> select = new PXSelectJoin <FATran, InnerJoin <FixedAsset, On <FixedAsset.assetID, Equal <FATran.assetID>, And <FixedAsset.recordType, Equal <FARecordType.assetType> > >, InnerJoin <FADetails, On <FADetails.assetID, Equal <FixedAsset.assetID> >, InnerJoin <FALocationHistoryCurrent, On <FALocationHistoryCurrent.assetID, Equal <FixedAsset.assetID> >, InnerJoin <FALocationHistory, On <FALocationHistory.assetID, Equal <FixedAsset.assetID>, And <FALocationHistory.periodID, Equal <FALocationHistoryCurrent.lastPeriodID>, And <FALocationHistory.revisionID, Equal <FALocationHistoryCurrent.lastRevisionID> > > > > > > >, Where <FATran.released, Equal <True>, And <FATran.finPeriodID, LessEqual <Current <AccBalanceByAssetFilter.periodID> >, And <FATran.bookID, Equal <Current <AccBalanceByAssetFilter.bookID> >, And2 <Where <FALocationHistory.fAAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >, And <FALocationHistory.fASubID, Equal <Current <AccBalanceByAssetFilter.subID> >, Or <FALocationHistory.accumulatedDepreciationAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >, And <FALocationHistory.accumulatedDepreciationSubID, Equal <Current <AccBalanceByAssetFilter.subID> > > > > >, And <Where <FATran.debitAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >, And <FATran.debitSubID, Equal <Current <AccBalanceByAssetFilter.subID> >, Or <FATran.creditAccountID, Equal <Current <AccBalanceByAssetFilter.accountID> >, And <FATran.creditSubID, Equal <Current <AccBalanceByAssetFilter.subID> > > > > > > > > > > >(this); if (filter.BranchID != null) { select.WhereAnd <Where <FALocationHistory.locationID, Equal <Current <AccBalanceByAssetFilter.branchID> > > >(); } Dictionary <int?, Amounts> dict = new Dictionary <int?, Amounts>(); foreach (PXResult <FATran, FixedAsset, FADetails, FALocationHistoryCurrent, FALocationHistory> res in select.Select()) { FATran tran = (FATran)res; FixedAsset asset = (FixedAsset)res; FADetails details = (FADetails)res; FALocationHistory location = (FALocationHistory)res; Amounts record = null; if (!dict.TryGetValue(asset.AssetID, out record)) { record = new Amounts { AssetID = asset.AssetID, Description = asset.Description, Status = details.Status, ClassID = asset.ClassID, DepreciateFromDate = details.DepreciateFromDate, BranchID = location.BranchID, Department = location.Department, ItdAmt = decimal.Zero, YtdAmt = decimal.Zero, PtdAmt = decimal.Zero }; } decimal tranAmt = tran.TranAmt ?? decimal.Zero; decimal amount = tran.DebitAccountID == tran.CreditAccountID && tran.DebitSubID == tran.CreditSubID ? decimal.Zero : tran.DebitAccountID == filter.AccountID && tran.DebitSubID == filter.SubID ? tranAmt : -tranAmt; record.ItdAmt += amount; record.YtdAmt += (FinPeriodIDAttribute.FinPeriodEqual(filter.PeriodID, tran.FinPeriodID, FinPeriodIDAttribute.FinPeriodComparison.Year) ? amount : decimal.Zero); record.PtdAmt += (filter.PeriodID == tran.FinPeriodID ? amount : decimal.Zero); dict[asset.AssetID] = record; } foreach (Amounts amt in dict.Values) { if (amt.ItdAmt != decimal.Zero || amt.YtdAmt != decimal.Zero || amt.PtdAmt != decimal.Zero) { yield return(amt); } } }
private static void ApplyPayment(ARPaymentEntry graph, ARAutoApplyParameters filter, ARPayment payment, List <ARInvoice> arInvoiceList, List <ARRegister> toRelease, out string warningRefNbr) { warningRefNbr = String.Empty; if (arInvoiceList.Any() == false) { return; } if (payment.DocDate > filter.ApplicationDate) { warningRefNbr = payment.RefNbr; PXProcessing <ARStatementCycle> .SetWarning(Messages.FuturePaymentWarning); return; } int invoiceIndex = 0; var paymentsViewIntoInvoiceList = new List <ARInvoice>(arInvoiceList); graph.Clear(); graph.Document.Current = payment; bool adjustmentAdded = false; while (graph.Document.Current.CuryUnappliedBal > 0 && invoiceIndex < paymentsViewIntoInvoiceList.Count) { if (graph.Document.Current.CuryApplAmt == null) { object curyapplamt = graph.Document.Cache.GetValueExt <ARPayment.curyApplAmt>(graph.Document.Current); if (curyapplamt is PXFieldState) { curyapplamt = ((PXFieldState)curyapplamt).Value; } graph.Document.Current.CuryApplAmt = (decimal?)curyapplamt; } graph.Document.Current.AdjDate = filter.ApplicationDate; FinPeriodIDAttribute.SetPeriodsByMaster <ARPayment.adjFinPeriodID>(graph.Document.Cache, graph.Document.Current, filter.FinPeriodID); graph.Document.Cache.Adjust <PX.Objects.AR.AROpenPeriodAttribute>().For <ARPayment.adjFinPeriodID>(atr => atr.RedefaultOnDateChanged = false); graph.Document.Cache.Update(graph.Document.Current); ARInvoice invoice = paymentsViewIntoInvoiceList[invoiceIndex]; var trans = invoice.PaymentsByLinesAllowed == true ? PXSelect <ARTran, Where <ARTran.tranType, Equal <Required <ARTran.tranType> >, And <ARTran.refNbr, Equal <Required <ARTran.refNbr> > > > > .Select(graph, invoice.DocType, invoice.RefNbr) : new PXResultset <ARTran>() { null }; foreach (ARTran tran in trans) { ARAdjust adj = new ARAdjust(); adj.AdjdDocType = invoice.DocType; adj.AdjdRefNbr = invoice.RefNbr; adj.AdjdLineNbr = tran?.LineNbr ?? 0; graph.AutoPaymentApp = true; adj = graph.Adjustments.Insert(adj); if (adj != null) { adjustmentAdded = true; if (adj.CuryDocBal <= 0m) { arInvoiceList.Remove(invoice); } } } invoiceIndex++; } if (adjustmentAdded) { graph.Save.Press(); if (filter.ReleaseBatchWhenFinished == true) { toRelease.Add(graph.Document.Current); } } }
public FinPeriod FindFinPeriodWithStartDate(DateTime?startDate) { return(FinPeriodIDAttribute.FindFinPeriodWithStartDate(_graph, startDate)); }
public FinPeriod FindFinPeriodWithEndDate(DateTime?endDate) { return(FinPeriodIDAttribute.FindFinPeriodWithEndDate(_graph, endDate)); }
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 string PeriodPlusPeriod(PXGraph graph, string financialPeriodID, short offset) { return(FinPeriodIDAttribute.PeriodPlusPeriod(graph, financialPeriodID, offset)); }