public void ReleaseDocProc(JournalEntry je, INRegister doc, INReleaseProcess_Extension.ReleaseDocProcDelegate baseMethod) { baseMethod(je, doc); foreach (INTranSplit row in this.Base.intransplit.Cache.Cached) { INTranSplit tranSplit = SelectINTranRcpSplit(Base, row.LotSerialNbr, row.InventoryID, row.SubItemID, row.SiteID, row.LocationID); if (tranSplit != null && row.DocType != INDocType.Receipt) { INTranSplitExt tranSplitExt = tranSplit.GetExtension <INTranSplitExt>(); Base.intransplit.Cache.SetValue <INTranSplitExt.usrCOO>(row, tranSplitExt.UsrCOO); Base.intransplit.Cache.SetValue <INTranSplitExt.usrDateCode>(row, tranSplitExt.UsrDateCode); } else { SOShipLineSplit lineSplit = SelectSOShipLineSplit(Base, row.LotSerialNbr, row.InventoryID, row.SubItemID, row.SiteID, row.LocationID); if (lineSplit == null) { continue; } SOShipLineSplitExt lineSplitExt = lineSplit.GetExtension <SOShipLineSplitExt>(); Base.intransplit.Cache.SetValue <INTranSplitExt.usrCOO>(row, lineSplitExt.UsrCOO); Base.intransplit.Cache.SetValue <INTranSplitExt.usrDateCode>(row, lineSplitExt.UsrDateCode); } Base.Caches[typeof(INTranSplit)].PersistUpdated(this.Base.Caches[typeof(INTranSplit)].Update(row)); PXTimeStampScope.PutPersisted(this.Base.Caches[typeof(INTranSplit)], row, PXDatabase.SelectTimeStamp()); } }
protected void _(Events.RowSelected <INTranSplit> e) { INRegister current = this.Base.INRegisterDataMember.Current; PXCache cache1 = e.Cache; INTranSplit row1 = e.Row; bool? hold; int num1; if (e.Row != null) { hold = current.Hold; bool flag = true; num1 = hold.GetValueOrDefault() == flag & hold.HasValue ? 1 : 0; } else { num1 = 0; } PXUIFieldAttribute.SetEnabled <INTranSplitExt.usrCOO>(cache1, (object)row1, num1 != 0); PXCache cache2 = e.Cache; INTranSplit row2 = e.Row; int num2; if (e.Row != null) { hold = current.Hold; bool flag = true; num2 = hold.GetValueOrDefault() == flag & hold.HasValue ? 1 : 0; } else { num2 = 0; } PXUIFieldAttribute.SetEnabled <INTranSplitExt.usrDateCode>(cache2, (object)row2, num2 != 0); }
protected virtual void INTranSplit_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { INTranSplit row = (INTranSplit)e.Row; INLotSerFilter filter = Filter.Current; if (row == null || filter == null) { return; } if (filter.ShowAdjUnitCost ?? false) { row.TranUnitCost = row.TotalQty == null || row.TotalQty == 0m ? 0m : (row.TotalCost + row.AdditionalCost) / row.TotalQty; } else { row.TranUnitCost = row.TotalQty == null || row.TotalQty == 0m ? 0m : (row.TotalCost) / row.TotalQty; } }
protected virtual IEnumerable internalResultRecords() { InventoryTranHistEnqFilter filter = Filter.Current; bool summaryByDay = filter.SummaryByDay ?? false; bool includeUnreleased = filter.IncludeUnreleased ?? false; var resultList = new List <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >(); if (filter.InventoryID == null) { PXDelegateResult emptyResult = new PXDelegateResult(); emptyResult.IsResultFiltered = true; emptyResult.IsResultSorted = true; emptyResult.IsResultTruncated = true; return(emptyResult); //empty } PXSelectBase <INTranSplit> cmd = new PXSelectReadonly2 <INTranSplit, InnerJoin <INTran, On <INTranSplit.FK.Tran>, InnerJoin <INSubItem, On <INTranSplit.FK.SubItem>, InnerJoin <INSite, On <INTran.FK.Site> > > >, 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 <INItemSiteHistByDay> cmdBegBalanceNew = new PXSelectReadonly2 <INItemSiteHistByDay, InnerJoin <INItemSiteHistDay, On <INItemSiteHistDay.inventoryID, Equal <INItemSiteHistByDay.inventoryID>, And <INItemSiteHistDay.siteID, Equal <INItemSiteHistByDay.siteID>, And <INItemSiteHistDay.subItemID, Equal <INItemSiteHistByDay.subItemID>, And <INItemSiteHistDay.locationID, Equal <INItemSiteHistByDay.locationID>, And <INItemSiteHistDay.sDate, Equal <INItemSiteHistByDay.lastActivityDate> > > > > >, InnerJoin <INSubItem, On <INSubItem.subItemID, Equal <INItemSiteHistByDay.subItemID> >, InnerJoin <INSite, On <INSite.siteID, Equal <INItemSiteHistByDay.siteID> > > > >, Where <INItemSiteHistByDay.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <INItemSiteHistByDay.date, Equal <Required <INItemSiteHistByDay.date> >, And <Match <INSite, Current <AccessInfo.userName> > > > > >(this); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD) && PXAccess.FeatureInstalled <FeaturesSet.subItem>()) { cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); cmdBegBalanceNew.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null && PXAccess.FeatureInstalled <FeaturesSet.warehouse>()) { cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1 && PXAccess.FeatureInstalled <FeaturesSet.warehouseLocation>()) // there are cases when filter.LocationID = -1 { cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); cmdBegBalanceNew.WhereAnd <Where <INItemSiteHistByDay.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; if (filter.StartDate != null) { foreach (PXResult <INItemSiteHistByDay, INItemSiteHistDay> res in cmdBegBalanceNew.Select(filter.StartDate)) { INItemSiteHistByDay byday = res; INItemSiteHistDay hist = res; cumulativeQty += ((byday.LastActivityDate != null && byday.Date != null && byday.Date.Value.Date == byday.LastActivityDate.Value.Date) ? hist.BegQty : hist.EndQty) ?? 0m; } if (includeUnreleased) { INSite site = INSite.PK.Find(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; string TranPeriodID; DateTime?PeriodStartDate; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); 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> > > >() .WhereAnd <Where <INTranSplit.released, Equal <False> > >() .AggregateNew <Aggregate < GroupBy <INTranSplit.inventoryID, GroupBy <INTranSplit.invtMult, Sum <INTranSplit.baseQty> > > > >()); int splitStartRow = 0; int splitTotalRows = 0; foreach (PXResult <INTranSplit> res in v2.Select(new object[0], new object[] { PeriodStartDate, filter.StartDate.Value }, new object[0], new string[0], new bool[0], new PXFilterRow[0], ref splitStartRow, 0, ref splitTotalRows)) { INTranSplit tsRec = res; cumulativeQty += (tsRec.InvtMult * tsRec.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> > > >(); } AlterSortsAndFilters(out string[] newSortColumns, out bool[] newDescendings, out bool sortsChanged, out PXFilterRow[] newFilters, out bool filtersChanged); //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 //Also, user can set a filter or sort by a column from result DAC (sortsChanged = true, filtersChanged = true) and need to get full result set. int startRow = 0; bool allowSelectWithTop = !sortsChanged && !filtersChanged && !PXView.ReverseOrder; int maximumRows = allowSelectWithTop ? PXView.StartRow + PXView.MaximumRows : 0; int 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, newDescendings, 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 (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, INTranSplit>(item, null, 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.DocType = ts_rec.DocType; item.RefNbr = ts_rec.RefNbr; item.LineNbr = ts_rec.LineNbr; item.SplitLineNbr = ts_rec.SplitLineNbr; 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, INTranSplit>(item, t_rec, ts_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } PXDelegateResult delegateResult = new PXDelegateResult(); delegateResult.IsResultFiltered = !filtersChanged; delegateResult.IsResultSorted = !sortsChanged; delegateResult.IsResultTruncated = totalRows > resultList.Count; if (!PXView.ReverseOrder) { delegateResult.AddRange(resultList); } else { var sortedList = PXView.Sort(resultList); delegateResult.AddRange(sortedList.Cast <PXResult <InventoryTranHistEnqResult, INTran, INTranSplit> >()); delegateResult.IsResultSorted = true; } return(delegateResult); }
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; INSite site = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(this, filter.SiteID); int calendarOrganizationID = PXAccess.GetParentOrganizationID(site?.BranchID) ?? FinPeriod.organizationID.MasterValue; try { TranPeriodID = FinPeriodRepository.GetPeriodIDFromDate(filter.StartDate, calendarOrganizationID); PeriodStartDate = FinPeriodRepository.PeriodStartDate(TranPeriodID, calendarOrganizationID); } catch (PXFinPeriodException) { TranPeriodID = null; PeriodStartDate = filter.StartDate; } int startRow = 0; int totalRows = 0; int maximumRows = 0; if (includeUnreleased) { PXSelectBase <OrganizationFinPeriod> periodCmd = new PXSelectGroupBy <OrganizationFinPeriod, Where <OrganizationFinPeriod.finPeriodID, LessEqual <Required <OrganizationFinPeriod.finPeriodID> >, And <OrganizationFinPeriod.iNClosed, Equal <False>, Or <OrganizationFinPeriod.finPeriodID, Equal <Required <OrganizationFinPeriod.finPeriodID> > > > >, Aggregate <GroupBy <OrganizationFinPeriod.finPeriodID> >, OrderBy <Asc <OrganizationFinPeriod.finPeriodID> > >(this); List <object> periodCmdParams = new List <object>() { TranPeriodID, TranPeriodID }; if (calendarOrganizationID != FinPeriod.organizationID.MasterValue) { periodCmd.WhereAnd <Where <OrganizationFinPeriod.organizationID, Equal <Required <OrganizationFinPeriod.organizationID> > > >(); periodCmdParams.Add(calendarOrganizationID); } OrganizationFinPeriod firstOpenOrCurrentClosedPeriod = periodCmd.SelectWindowed(0, 1, periodCmdParams.ToArray()); if (firstOpenOrCurrentClosedPeriod != null) { TranPeriodID = firstOpenOrCurrentClosedPeriod.FinPeriodID; PeriodStartDate = FinPeriodRepository.PeriodStartDate(firstOpenOrCurrentClosedPeriod.FinPeriodID, calendarOrganizationID); } 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)); }
protected virtual void INRegister_TransferNbr_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { INTran newtran = null; INTran prev_tran = null; int? prev_linenbr = null; using (new PXReadBranchRestrictedScope()) { foreach (PXResult <INTran, INTranSplit, INItemPlan, INSite> res in PXSelectJoin <INTran, InnerJoin <INTranSplit, On <INTranSplit.tranType, Equal <INTran.tranType>, And <INTranSplit.refNbr, Equal <INTran.refNbr>, And <INTranSplit.lineNbr, Equal <INTran.lineNbr> > > >, InnerJoin <INItemPlan, On <INItemPlan.planID, Equal <INTranSplit.planID>, And <INItemPlan.planType, Equal <INPlanConstants.plan42> > >, InnerJoin <INSite, On <INSite.siteID, Equal <INTran.toSiteID> > > > >, Where <INTran.docType, Equal <Required <INTran.docType> >, And <INTran.refNbr, Equal <Required <INTran.refNbr> >, And <INTran.docType, Equal <INDocType.transfer>, And <INTran.invtMult, Equal <shortMinus1> > > > >, OrderBy <Asc <INTran.tranType, Asc <INTran.refNbr, Asc <INTran.lineNbr> > > > > .Select(this, INDocType.Transfer, ((INRegister)e.Row).TransferNbr)) { INTran tran = res; INTranSplit split = res; INSite site = res; if (object.Equals(prev_tran, tran) == false) { if (!object.Equals(receipt.Current.BranchID, site.BranchID)) { INRegister copy = PXCache <INRegister> .CreateCopy(receipt.Current); copy.BranchID = site.BranchID; receipt.Update(copy); } newtran = PXCache <INTran> .CreateCopy(tran); newtran.OrigBranchID = newtran.BranchID; newtran.OrigTranType = newtran.TranType; newtran.OrigRefNbr = newtran.RefNbr; newtran.OrigLineNbr = newtran.LineNbr; newtran.BranchID = site.BranchID; newtran.DocType = ((INRegister)e.Row).DocType; newtran.RefNbr = ((INRegister)e.Row).RefNbr; newtran.LineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTran.lineNbr>(transactions.Cache, e.Row); newtran.InvtMult = (short)1; newtran.SiteID = newtran.ToSiteID; newtran.LocationID = newtran.ToLocationID; newtran.ToSiteID = null; newtran.ToLocationID = null; newtran.Qty = 0m; newtran.BaseQty = 0m; newtran.Released = false; newtran.InvtAcctID = null; newtran.InvtSubID = null; newtran.ReasonCode = null; newtran.ARDocType = null; newtran.ARRefNbr = null; newtran.ARLineNbr = null; newtran.ProjectID = null; newtran.TaskID = null; splits.Current = null; newtran = transactions.Insert(newtran); if (splits.Current != null) { splits.Delete(splits.Current); } prev_tran = tran; prev_linenbr = newtran.LineNbr; } INTranSplit newsplit = PXCache <INTranSplit> .CreateCopy(split); newsplit.DocType = ((INRegister)e.Row).DocType; newsplit.RefNbr = ((INRegister)e.Row).RefNbr; newsplit.LineNbr = prev_linenbr; newsplit.SplitLineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTranSplit.splitLineNbr>(splits.Cache, e.Row); newsplit.InvtMult = (short)1; newsplit.SiteID = tran.ToSiteID; newsplit.LocationID = tran.ToLocationID; newsplit.PlanID = null; newsplit.Released = false; newsplit.ProjectID = null; newsplit.TaskID = null; newsplit = splits.Insert(newsplit); if (newtran.BaseQty == tran.BaseQty) { //fix conversion rounding newtran = PXCache <INTran> .CreateCopy(newtran); newtran.Qty = tran.Qty; newtran.UnitCost = PXPriceCostAttribute.Round(tran.Qty != 0m ? (decimal)(tran.TranCost / tran.Qty) : 0m); newtran.TranCost = tran.TranCost; newtran = transactions.Update(newtran); } } } }
public virtual void IntegrityCheckProc(INItemSiteSummary itemsite, string minPeriod, bool replanBackorders) { using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan, LeftJoin <Note, On <Note.noteID, Equal <INItemPlan.refNoteID> > >, Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <Note.noteID, IsNull> > > > .SelectMultiBound(this, new object[] { itemsite })) { PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ)); } foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan, InnerJoin <INRegister, On <INRegister.noteID, Equal <INItemPlan.refNoteID>, And <INRegister.siteID, Equal <INItemPlan.siteID> > > >, Where <INRegister.docType, Equal <INDocType.transfer>, And <INRegister.released, Equal <boolTrue>, And <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > > > .SelectMultiBound(this, new object[] { itemsite })) { PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ)); } foreach (PXResult <INTranSplit, INRegister, INSite, INItemSite> res in PXSelectJoin <INTranSplit, InnerJoin <INRegister, On <INRegister.docType, Equal <INTranSplit.docType>, And <INRegister.refNbr, Equal <INTranSplit.refNbr> > >, InnerJoin <INSite, On <INSite.siteID, Equal <INRegister.toSiteID> >, LeftJoin <INItemSite, On <INItemSite.inventoryID, Equal <INTranSplit.inventoryID>, And <INItemSite.siteID, Equal <INRegister.toSiteID> > >, LeftJoin <INTran, On <INTran.origTranType, Equal <INTranSplit.tranType>, And <INTran.origRefNbr, Equal <INTranSplit.refNbr>, And <INTran.origLineNbr, Equal <INTranSplit.lineNbr> > > >, LeftJoin <INItemPlan, On <INItemPlan.planID, Equal <INTranSplit.planID> > > > > > >, Where <INRegister.docType, Equal <INDocType.transfer>, And2 <Where <INRegister.released, Equal <boolTrue>, And <INTranSplit.released, Equal <boolTrue>, Or <INRegister.released, Equal <boolFalse> > > >, And <INTranSplit.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTranSplit.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTranSplit.invtMult, Equal <shortMinus1>, And <INItemPlan.planID, IsNull, And <INTran.refNbr, IsNull> > > > > > > > .SelectMultiBound(this, new object[] { itemsite })) { INTranSplit split = res; INRegister doc = res; if (split.TransferType == INTransferType.OneStep && doc.Released == true) { if (doc.TransferType == INTransferType.OneStep) { doc.TransferType = INTransferType.TwoStep; Caches[typeof(INRegister)].Update(doc); } split.TransferType = INTransferType.TwoStep; } INItemPlan plan = INItemPlanIDAttribute.DefaultValues(this.Caches[typeof(INTranSplit)], res); if (plan.LocationID == null) { plan.LocationID = ((INItemSite)res).DfltReceiptLocationID ?? ((INSite)res).ReceiptLocationID; } plan = (INItemPlan)this.Caches[typeof(INItemPlan)].Insert(plan); split.PlanID = plan.PlanID; Caches[typeof(INTranSplit)].SetStatus(split, PXEntryStatus.Updated); } PXDatabase.Update <INSiteStatus>( new PXDataFieldRestrict <INSiteStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict <INSiteStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldAssign <INSiteStatus.qtyAvail>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyHardAvail>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyNotAvail>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyINIssues>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyINReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyInTransit>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyINReplaned>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOBooked>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOShipped>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOShipping>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySOFixed>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtySODropShip>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INSiteStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m) ); PXDatabase.Update <INLocationStatus>( new PXDataFieldRestrict <INLocationStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict <INLocationStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldAssign <INLocationStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INLocationStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INLocationStatus.qtyINIssues>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyINReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyInTransit>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOBooked>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOShipped>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOShipping>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySOFixed>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtySODropShip>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLocationStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m) ); PXDatabase.Update <INLotSerialStatus>( new PXDataFieldRestrict <INLotSerialStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict <INLotSerialStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldAssign <INLotSerialStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INLotSerialStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INLotSerialStatus.qtyINIssues>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyINReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyInTransit>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOBooked>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOShipped>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOShipping>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySOFixed>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtySODropShip>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m), new PXDataFieldAssign <INLotSerialStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m) ); PXDatabase.Update <INItemLotSerial>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldAssign("QtyAvail", PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign("QtyHardAvail", PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign("QtyINTransit", PXDbType.Decimal, 0m) ); PXDatabase.Update <INSiteLotSerial>( new PXDataFieldRestrict <INSiteLotSerial.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict <INSiteLotSerial.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldAssign <INSiteLotSerial.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INSiteLotSerial.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"), new PXDataFieldAssign <INSiteLotSerial.qtyInTransit>(PXDbType.Decimal, 0m) ); foreach (PXResult <ReadOnlyLocationStatus, INLocation> res in PXSelectJoinGroupBy <ReadOnlyLocationStatus, InnerJoin <INLocation, On <INLocation.locationID, Equal <ReadOnlyLocationStatus.locationID> > >, Where <ReadOnlyLocationStatus.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <ReadOnlyLocationStatus.siteID, Equal <Current <INItemSiteSummary.siteID> > > >, Aggregate <GroupBy <ReadOnlyLocationStatus.inventoryID, GroupBy <ReadOnlyLocationStatus.siteID, GroupBy <ReadOnlyLocationStatus.subItemID, GroupBy <INLocation.inclQtyAvail, Sum <ReadOnlyLocationStatus.qtyOnHand> > > > > > > .SelectMultiBound(this, new object[] { itemsite })) { SiteStatus status = new SiteStatus(); status.InventoryID = ((ReadOnlyLocationStatus)res).InventoryID; status.SubItemID = ((ReadOnlyLocationStatus)res).SubItemID; status.SiteID = ((ReadOnlyLocationStatus)res).SiteID; status = (SiteStatus)sitestatus.Cache.Insert(status); if (((INLocation)res).InclQtyAvail == true) { status.QtyAvail += ((ReadOnlyLocationStatus)res).QtyOnHand; status.QtyHardAvail += ((ReadOnlyLocationStatus)res).QtyOnHand; } else { status.QtyNotAvail += ((ReadOnlyLocationStatus)res).QtyOnHand; } } INPlanType plan60 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan60> > > .Select(this); INPlanType plan61 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan61> > > .Select(this); INPlanType plan70 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan70> > > .Select(this); INPlanType plan74 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan74> > > .Select(this); INPlanType plan76 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan76> > > .Select(this); INPlanType plan42 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan42> > > .Select(this); INPlanType plan44 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan44> > > .Select(this); foreach (PXResult <INItemPlan, INPlanType, SOShipLineSplit, POReceiptLineSplit> res in PXSelectJoin <INItemPlan, InnerJoin <INPlanType, On <INPlanType.planType, Equal <INItemPlan.planType> >, LeftJoin <SOShipLineSplit, On <SOShipLineSplit.planID, Equal <INItemPlan.planID> >, LeftJoin <POReceiptLineSplit, On <POReceiptLineSplit.planID, Equal <INItemPlan.planID> > > > >, Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > .SelectMultiBound(this, new object[] { itemsite })) { INItemPlan plan = (INItemPlan)res; INPlanType plantype = (INPlanType)res; INPlanType locplantype; SOShipLineSplit sosplit = (SOShipLineSplit)res; POReceiptLineSplit posplit = (POReceiptLineSplit)res; if (plan.InventoryID != null && plan.SubItemID != null && plan.SiteID != null) { switch (plan.PlanType) { case INPlanConstants.Plan61: case INPlanConstants.Plan63: locplantype = plantype; if (sosplit.ShipmentNbr != null) { SOOrderType ordetype = PXSelect <SOOrderType, Where <SOOrderType.orderType, Equal <Current <SOShipLineSplit.origOrderType> > > > .SelectSingleBound(this, new object[] { sosplit }); if (plan.OrigPlanType == null) { plan.OrigPlanType = ordetype.OrderPlanType; } if (plan.OrigPlanType == INPlanConstants.Plan60 && sosplit.IsComponentItem != true) { plantype = plantype - plan60; } if ((plan.OrigPlanType == INPlanConstants.Plan61 || plan.OrigPlanType == INPlanConstants.Plan63) && sosplit.IsComponentItem != true) { plantype = plantype - plan61; } } break; case INPlanConstants.Plan71: case INPlanConstants.Plan72: locplantype = plantype; if (posplit.ReceiptNbr == null) { PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, plan.PlanID, PXComp.EQ)); continue; } if (posplit.PONbr != null) { plantype = plantype - plan70; } break; case INPlanConstants.Plan77: locplantype = plantype; if (posplit.ReceiptNbr != null && posplit.PONbr != null) { plantype = plantype - plan76; } break; case INPlanConstants.Plan75: locplantype = plantype; if (posplit.ReceiptNbr != null && posplit.PONbr != null) { plantype = plantype - plan74; } break; case INPlanConstants.Plan43: case INPlanConstants.Plan45: if (plan.OrigPlanType == INPlanConstants.Plan44) { plantype = plantype - plan44; } if (plan.OrigPlanType == INPlanConstants.Plan42) { plantype = plantype - plan42; } locplantype = plantype; break; default: locplantype = plantype; break; } if (plan.LocationID != null) { LocationStatus item = INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LocationStatus>(this, plan, locplantype, true); INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, (bool)item.InclQtyAvail); if (!string.IsNullOrEmpty(plan.LotSerialNbr)) { INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LotSerialStatus>(this, plan, locplantype, true); INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, locplantype, true); INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, locplantype, true); } } else { INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, true); if (!string.IsNullOrEmpty(plan.LotSerialNbr)) { //TODO: check if LotSerialNbr was allocated on OrigPlanType INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, plantype, true); INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, plantype, true); } } } } if (replanBackorders) { INReleaseProcess.ReplanBackOrders(this); initemplan.Cache.Persist(PXDBOperation.Insert); initemplan.Cache.Persist(PXDBOperation.Update); } Caches[typeof(INTranSplit)].Persist(PXDBOperation.Update); sitestatus.Cache.Persist(PXDBOperation.Insert); sitestatus.Cache.Persist(PXDBOperation.Update); locationstatus.Cache.Persist(PXDBOperation.Insert); locationstatus.Cache.Persist(PXDBOperation.Update); lotserialstatus.Cache.Persist(PXDBOperation.Insert); lotserialstatus.Cache.Persist(PXDBOperation.Update); itemlotserial.Cache.Persist(PXDBOperation.Insert); itemlotserial.Cache.Persist(PXDBOperation.Update); sitelotserial.Cache.Persist(PXDBOperation.Insert); sitelotserial.Cache.Persist(PXDBOperation.Update); if (minPeriod != null) { FinPeriod period = PXSelect <FinPeriod, Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > > .SelectWindowed(this, 0, 1, minPeriod); if (period == null) { return; } DateTime startDate = (DateTime)period.StartDate; PXDatabase.Delete <INItemCostHist>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE) ); PXDatabase.Delete <INItemSalesHistD>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("QtyPlanSales", PXDbType.Decimal, 0m), new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE) ); PXDatabase.Delete <INItemCustSalesStats>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("LastDate", PXDbType.DateTime, 8, startDate, PXComp.GE)); PXDatabase.Update <INItemSalesHistD>( new PXDataFieldAssign("QtyIssues", PXDbType.Decimal, 0m), new PXDataFieldAssign("QtyExcluded", PXDbType.Decimal, 0m), new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE) ); foreach (INLocation loc in PXSelectReadonly2 <INLocation, InnerJoin <INItemCostHist, On <INItemCostHist.costSiteID, Equal <INLocation.locationID> > >, Where <INLocation.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INItemCostHist.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> > > > > .SelectMultiBound(this, new object[] { itemsite })) { PXDatabase.Delete <INItemCostHist>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, loc.LocationID, PXComp.EQ), new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE) ); } PXDatabase.Delete <INItemSiteHist>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE) ); PXDatabase.Delete <INItemSiteHistD>( new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ), new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ), new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE) ); INTran prev_tran = null; foreach (PXResult <INTran, INTranSplit> res in PXSelectReadonly2 <INTran, InnerJoin <INTranSplit, On <INTranSplit.tranType, Equal <INTran.tranType>, And <INTranSplit.refNbr, Equal <INTran.refNbr>, And <INTranSplit.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTran.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > >, OrderBy <Asc <INTran.tranType, Asc <INTran.refNbr, Asc <INTran.lineNbr> > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod)) { INTran tran = res; INTranSplit split = res; if (!Caches[typeof(INTran)].ObjectsEqual(prev_tran, tran)) { INReleaseProcess.UpdateSalesHistD(this, tran); INReleaseProcess.UpdateCustSalesStats(this, tran); prev_tran = tran; } if (split.BaseQty != 0m) { INReleaseProcess.UpdateSiteHist(this, res, split); INReleaseProcess.UpdateSiteHistD(this, split); } } foreach (PXResult <INTran, INTranCost> res in PXSelectReadonly2 <INTran, InnerJoin <INTranCost, On <INTranCost.tranType, Equal <INTran.tranType>, And <INTranCost.refNbr, Equal <INTran.refNbr>, And <INTranCost.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTranCost.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod)) { INReleaseProcess.UpdateCostHist(this, (INTranCost)res, (INTran)res); } itemcosthist.Cache.Persist(PXDBOperation.Insert); itemcosthist.Cache.Persist(PXDBOperation.Update); itemsitehist.Cache.Persist(PXDBOperation.Insert); itemsitehist.Cache.Persist(PXDBOperation.Update); itemsitehistd.Cache.Persist(PXDBOperation.Insert); itemsitehistd.Cache.Persist(PXDBOperation.Update); itemsalehistd.Cache.Persist(PXDBOperation.Insert); itemsalehistd.Cache.Persist(PXDBOperation.Update); itemcustsalesstats.Cache.Persist(PXDBOperation.Insert); itemcustsalesstats.Cache.Persist(PXDBOperation.Update); } ts.Complete(); } sitestatus.Cache.Persisted(false); locationstatus.Cache.Persisted(false); lotserialstatus.Cache.Persisted(false); itemcosthist.Cache.Persisted(false); itemsitehist.Cache.Persisted(false); itemsitehistd.Cache.Persisted(false); } }
protected virtual IEnumerable resultRecords() { 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 } // it's better for perfomance to calc. BegQty in the separate GROUP BY query before main.. but currently as is PXSelectBase <INTranSplit> cmd = new PXSelectReadonly3 <INTranSplit, InnerJoin <INTran, On <INTran.tranType, Equal <INTranSplit.tranType>, 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> > > > >, // OrderBy<Asc<INTranSplit.inventoryID, Asc<INTranSplit.tranDate>>>>(this); // additional order by LastModifiedDateTime ??? OrderBy <Asc <INTranSplit.tranDate, Asc <INTranSplit.lastModifiedDateTime> > > >(this); cmd.WhereAnd <Where <INTranSplit.inventoryID, Equal <Current <InventoryTranHistEnqFilter.inventoryID> >, And <Match <INSite, Current <AccessInfo.userName> > > > >(); if (!SubCDUtils.IsSubCDEmpty(filter.SubItemCD)) { cmd.WhereAnd <Where <INSubItem.subItemCD, Like <Current <InventoryTranHistEnqFilter.subItemCDWildcard> > > >(); } if (filter.SiteID != null) { cmd.WhereAnd <Where <INTranSplit.siteID, Equal <Current <InventoryTranHistEnqFilter.siteID> > > >(); } if ((filter.LocationID ?? -1) != -1) // there are cases when filter.LocationID = -1 { cmd.WhereAnd <Where <INTranSplit.locationID, Equal <Current <InventoryTranHistEnqFilter.locationID> > > >(); } if ((filter.LotSerialNbr ?? "") != "") { cmd.WhereAnd <Where <INTranSplit.lotSerialNbr, Like <Current <InventoryTranHistEnqFilter.lotSerialNbrWildcard> > > >(); } if (!includeUnreleased) { cmd.WhereAnd <Where <INTranSplit.released, Equal <boolTrue> > >(); } // commented because we need all the trans to calc BegQty // 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> > > >(); } PXResultset <INTranSplit> intermediateResult = (PXResultset <INTranSplit>)cmd.Select(); decimal cumulativeQty = 0m; 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) { if ((resultList.Count > 0) && (((InventoryTranHistEnqResult)resultList[resultList.Count - 1]).TranDate == ts_rec.TranDate)) { InventoryTranHistEnqResult lastItem = resultList[resultList.Count - 1]; if (ts_rec.InvtMult * ts_rec.BaseQty >= 0) { lastItem.QtyIn += ts_rec.InvtMult * ts_rec.BaseQty; } else { lastItem.QtyOut -= ts_rec.InvtMult * ts_rec.BaseQty; } lastItem.EndQty += ts_rec.InvtMult * ts_rec.BaseQty; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; if (ts_rec.InvtMult * ts_rec.BaseQty >= 0) { item.QtyIn = ts_rec.InvtMult * ts_rec.BaseQty; item.QtyOut = 0m; } else { item.QtyIn = 0m; item.QtyOut = -ts_rec.InvtMult * ts_rec.BaseQty; } item.EndQty = item.BegQty + (ts_rec.InvtMult * ts_rec.BaseQty); item.GridLineNbr = ++gridLineNbr; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, null)); } cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } else { InventoryTranHistEnqResult item = new InventoryTranHistEnqResult(); item.BegQty = cumulativeQty; item.TranDate = ts_rec.TranDate; if (ts_rec.InvtMult * ts_rec.BaseQty >= 0) { item.QtyIn = ts_rec.InvtMult * ts_rec.BaseQty; item.QtyOut = 0m; } else { item.QtyIn = 0m; item.QtyOut = -ts_rec.InvtMult * ts_rec.BaseQty; } item.EndQty = item.BegQty + (ts_rec.InvtMult * ts_rec.BaseQty); 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; resultList.Add(new PXResult <InventoryTranHistEnqResult, INTran>(item, t_rec)); cumulativeQty += (ts_rec.InvtMult * ts_rec.BaseQty) ?? 0m; } } } return(resultList); }