protected virtual IEnumerable ViewInventoryTranDet(PXAdapter adapter) { if ((this.ResultRecords.Current != null) && (this.Filter.Current != null)) { INItemSiteHist res = this.ResultRecords.Current; InventoryTranSumEnqFilter currentFilter = this.Filter.Current; InventoryTranDetEnq graph = PXGraph.CreateInstance <InventoryTranDetEnq>(); graph.Filter.Current.ByFinancialPeriod = currentFilter.ByFinancialPeriod; graph.Filter.Current.FinPeriodID = currentFilter.FinPeriodID; graph.Filter.Current.InventoryID = res.InventoryID; if (res.SubItemID != null) { INSubItem foundSubItem = INSubItem.PK.Find(graph, res.SubItemID); if (foundSubItem != null) { graph.Filter.Current.SubItemCD = foundSubItem.SubItemCD; } } graph.Filter.Current.SiteID = res.SiteID; // possibly null graph.Filter.Current.LocationID = res.LocationID; throw new PXRedirectRequiredException(graph, "Inventory Transaction Details"); } return(adapter.Get()); }
protected virtual void INSubItem_RowDeleting(PXCache sender, PXRowDeletingEventArgs e) { INSubItem row = e.Row as INSubItem; if (row != null) { INSiteStatus status = PXSelect <INSiteStatus, Where <INSiteStatus.subItemID, Equal <Required <INSubItem.subItemID> > > > .SelectWindowed(this, 0, 1, row.SubItemID); if (status != null) { throw new PXSetPropertyException(Messages.SubitemDeleteError); } INItemXRef itemRef = PXSelect <INItemXRef, Where <INItemXRef.subItemID, Equal <Required <INSubItem.subItemID> > > > .SelectWindowed(this, 0, 1, row.SubItemID); if (itemRef != null) { throw new PXSetPropertyException(Messages.SubitemDeleteError); } } }
public virtual IEnumerable InventorySummary(PXAdapter adapter) { PXCache tCache = transactions.Cache; INTran line = transactions.Current; if (line == null) { return(adapter.Get()); } InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <INTran.inventoryID>(tCache, line); if (item != null && item.StkItem == true) { INSubItem sbitem = (INSubItem)PXSelectorAttribute.Select <INTran.subItemID>(tCache, line); InventorySummaryEnq.Redirect(item.InventoryID, ((sbitem != null) ? sbitem.SubItemCD : null), line.SiteID, line.LocationID); } return(adapter.Get()); }
protected virtual void INKitSpecStkDet_CompSubItemID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { INKitSpecStkDet row = e.Row as INKitSpecStkDet; if (row != null) { PXSelectBase <INKitSpecStkDet> select = new PXSelect <INKitSpecStkDet, Where <INKitSpecStkDet.kitInventoryID, Equal <Current <INKitSpecHdr.kitInventoryID> >, And <INKitSpecStkDet.revisionID, Equal <Current <INKitSpecHdr.revisionID> >, And <INKitSpecStkDet.compInventoryID, Equal <Required <INKitSpecStkDet.compInventoryID> >, And <INKitSpecStkDet.compSubItemID, Equal <Required <INKitSpecStkDet.compSubItemID> > > > > > >(this); PXResultset <INKitSpecStkDet> res = select.Select(row.CompInventoryID, e.NewValue); if (res.Count > 0) { INSubItem subitem = INSubItem.PK.Find(this, (int?)e.NewValue); var ex = new PXSetPropertyException(Messages.KitItemMustBeUniqueAccrosSubItems); ex.ErrorValue = subitem?.SubItemCD; throw ex; } } }
protected virtual IEnumerable internalResultRecords() { const bool useItemCostHistoryToOptimizeBalanceCalculation = true; // false to debug and ensure that INItemCostHistory corresponds to INCostTran InventoryTranByAcctEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.tranType>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.docRefNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.subItemCD>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.siteID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.locationID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.accountID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.subID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.inventoryID>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.costAdj>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.finPerNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.tranPerNbr>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.qty>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible <InventoryTranByAcctEnqResult.unitCost>(ResultRecords.Cache, null, !summaryByDay); PXUIFieldAttribute.SetVisible(Tran.Cache, null, !summaryByDay); var resultList = new List <PXResult <InventoryTranByAcctEnqResult, INTran> >(); decimal cumulativeBalance = 0m; if (filter.AccountID == null) { return(resultList); //empty } if (filter.FinPeriodID == null) { return(resultList); //empty } if (useItemCostHistoryToOptimizeBalanceCalculation) { PXSelectBase <INItemCostHist> cmd_CostHist = new PXSelectJoinGroupBy <INItemCostHist, InnerJoin <Sub, On <Sub.subID, Equal <INItemCostHist.subID> > >, Where <INItemCostHist.finPeriodID, Less <Current <InventoryTranByAcctEnqFilter.finPeriodID> > >, Aggregate < Sum <INItemCostHist.tranYtdCost, Sum <INItemCostHist.tranBegCost, Sum <INItemCostHist.finYtdCost, Sum <INItemCostHist.finBegCost> > > > > >(this); //if (filter.AccountID != null) // checked above { cmd_CostHist.WhereAnd <Where <INItemCostHist.accountID, Equal <Current <InventoryTranByAcctEnqFilter.accountID> > > >(); } if (!SubCDUtils.IsSubCDEmpty(filter.SubCD)) { cmd_CostHist.WhereAnd <Where <Sub.subCD, Like <Current <InventoryTranByAcctEnqFilter.subCDWildcard> > > >(); } PXResultset <INItemCostHist> costHistResult = (PXResultset <INItemCostHist>)cmd_CostHist.Select(); if (costHistResult.Count == 1) // 0 is possible too { if (filter.ByFinancialPeriod == true) { cumulativeBalance += (((INItemCostHist)costHistResult[0]).FinYtdCost ?? 0m) - (((INItemCostHist)costHistResult[0]).FinBegCost ?? 0m); } else { cumulativeBalance += (((INItemCostHist)costHistResult[0]).TranYtdCost ?? 0m) - (((INItemCostHist)costHistResult[0]).TranBegCost ?? 0m); } } } PXSelectBase <INTranCost> cmd = new PXSelectReadonly2 <INTranCost, InnerJoin <INTran, On <INTran.tranType, Equal <INTranCost.tranType>, And <INTran.refNbr, Equal <INTranCost.refNbr>, And <INTran.lineNbr, Equal <INTranCost.lineNbr> > > >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INTranCost.inventoryID>, And <Match <InventoryItem, Current <AccessInfo.userName> > > >, InnerJoin <Sub, On <Sub.subID, Equal <INTranCost.invtSubID> >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INTranCost.costSubItemID> >, LeftJoin <INSite, On <INSite.siteID, Equal <INTranCost.costSiteID> >, LeftJoin <INLocation, On <INLocation.locationID, Equal <INTranCost.costSiteID> >, LeftJoin <INCostStatus, On <INTranCost.costID, Equal <INCostStatus.costID> > > > > > > > >, Where <INSite.siteID, IsNull, Or <Match <INSite, Current <AccessInfo.userName> > > >, OrderBy <Asc <INTranCost.tranDate, Asc <INTranCost.createdDateTime> > > >(this); //if (filter.FinPeriodID != null) // checked above if (filter.ByFinancialPeriod == true) { cmd.WhereAnd <Where <INTranCost.finPeriodID, Equal <Current <InventoryTranByAcctEnqFilter.finPeriodID> > > >(); } else { cmd.WhereAnd <Where <INTranCost.tranPeriodID, Equal <Current <InventoryTranByAcctEnqFilter.finPeriodID> > > >(); } //if (filter.AccountID != null) // checked above { cmd.WhereAnd <Where <INTranCost.invtAcctID, Equal <Current <InventoryTranByAcctEnqFilter.accountID> > > >(); } if (!SubCDUtils.IsSubCDEmpty(filter.SubCD)) { cmd.WhereAnd <Where <Sub.subCD, Like <Current <InventoryTranByAcctEnqFilter.subCDWildcard> > > >(); } if (filter.EndDate != null) { cmd.WhereAnd <Where <INTranCost.tranDate, LessEqual <Current <InventoryTranByAcctEnqFilter.endDate> > > >(); } if (filter.InventoryID != null) { cmd.WhereAnd <Where <INTranCost.inventoryID, Equal <Current <InventoryTranByAcctEnqFilter.inventoryID> > > >(); } if (filter.SiteID != null) { cmd.WhereAnd <Where <INTranCost.costSiteID, Equal <Current <InventoryTranByAcctEnqFilter.siteID> > > >(); } int gridLineNbr = 0; foreach (PXResult <INTranCost, INTran, InventoryItem, Sub, INSubItem, INSite, INLocation, INCostStatus> it in cmd.Select()) { INTranCost tc_rec = (INTranCost)it; INTran t_rec = (INTran)it; INSite s_rec = (INSite)it; INLocation l_rec = (INLocation)it; INSubItem si_rec = (INSubItem)it; INCostStatus cs_rec = (INCostStatus)it; decimal rowCost = (tc_rec.InvtMult * tc_rec.TranCost) ?? 0m; if (tc_rec.TranDate < filter.StartDate) { cumulativeBalance += rowCost; } else { if (summaryByDay) { if ((resultList.Count > 0) && (((InventoryTranByAcctEnqResult)resultList[resultList.Count - 1]).TranDate == tc_rec.TranDate)) { InventoryTranByAcctEnqResult lastItem = resultList[resultList.Count - 1]; if (rowCost >= 0) { lastItem.Debit += rowCost; } else { lastItem.Credit -= rowCost; } lastItem.EndBalance += rowCost; resultList[resultList.Count - 1] = new PXResult <InventoryTranByAcctEnqResult, INTran>(lastItem, null); } else { InventoryTranByAcctEnqResult item = new InventoryTranByAcctEnqResult(); item.BegBalance = cumulativeBalance; item.TranDate = tc_rec.TranDate; if (rowCost >= 0) { item.Debit = rowCost; item.Credit = 0m; } else { item.Debit = 0m; item.Credit = -rowCost; } item.EndBalance = item.BegBalance + rowCost; item.GridLineNbr = ++gridLineNbr; item.CreatedDateTime = tc_rec.CreatedDateTime; resultList.Add(new PXResult <InventoryTranByAcctEnqResult, INTran>(item, null)); } cumulativeBalance += rowCost; } else { InventoryTranByAcctEnqResult item = new InventoryTranByAcctEnqResult(); item.BegBalance = cumulativeBalance; item.TranDate = tc_rec.TranDate; if (rowCost >= 0) { item.Debit = rowCost; item.Credit = 0m; } else { item.Debit = 0m; item.Credit = -rowCost; } item.EndBalance = item.BegBalance + rowCost; item.AccountID = tc_rec.InvtAcctID; item.SubID = tc_rec.InvtSubID; item.TranType = tc_rec.TranType; item.DocType = t_rec.DocType; item.DocRefNbr = tc_rec.RefNbr; item.ReceiptNbr = cs_rec.ReceiptNbr; item.InventoryID = tc_rec.InventoryID; item.SubItemCD = si_rec.SubItemCD; if (s_rec.SiteID != null) { item.SiteID = s_rec.SiteID; item.LocationID = null; } else if (l_rec.LocationID != null) //though it's more or less guaranteed { item.SiteID = l_rec.SiteID; item.LocationID = l_rec.LocationID; } item.TranDate = tc_rec.TranDate; item.FinPerNbr = tc_rec.FinPeriodID; item.TranPerNbr = tc_rec.TranPeriodID; item.Qty = tc_rec.Qty * tc_rec.InvtMult; item.UnitCost = (tc_rec.Qty ?? 0m) == 0m ? null : ((tc_rec.TranCost ?? 0m) + (tc_rec.VarCost ?? 0m)) / tc_rec.Qty; item.CostAdj = tc_rec.CostRefNbr != tc_rec.RefNbr; item.GridLineNbr = ++gridLineNbr; item.CreatedDateTime = tc_rec.CreatedDateTime; resultList.Add(new PXResult <InventoryTranByAcctEnqResult, INTran>(item, t_rec)); cumulativeBalance += rowCost; } } } return(resultList); }