public virtual void RevalueInventory(INUpdateStdCostRecord itemsite) { using (new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { if (je.adjustment.Current == null) { je.adjustment.Cache.Insert(); } foreach ( PXResult <INCostStatus, InventoryItem, INSite, INPostClass, INItemSite> res in incoststatus.View.SelectMultiBound(new object[] { itemsite })) { INCostStatus layer = res; INSite site = res; INTran tran = new INTran(); if (((INCostStatus)res).LayerType == INLayerType.Oversold) { tran.TranType = INTranType.NegativeCostAdjustment; } else { tran.TranType = INTranType.StandardCostAdjustment; } tran.BranchID = site.BranchID; tran.InvtAcctID = layer.AccountID; tran.InvtSubID = layer.SubID; tran.AcctID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevAcctID> (je, (InventoryItem)res, (INSite)res, (INPostClass)res); tran.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevSubID> (je, (InventoryItem)res, (INSite)res, (INPostClass)res); tran.InventoryID = layer.InventoryID; tran.SubItemID = layer.CostSubItemID; tran.SiteID = layer.CostSiteID; tran.Qty = 0m; tran.TranCost = PXDBCurrencyAttribute.BaseRound(this, (decimal)(layer.QtyOnHand * itemsite.StdCost)) - layer.TotalCost; je.transactions.Insert(tran); } if (je.transactions.Select().Count == 0) { je.Clear(); } else { je.Save.Press(); PXProcessing <INUpdateStdCostRecord> .SetInfo(string.Format(Messages.AdjstmentCreated, je.adjustment.Current.RefNbr)); } ts.Complete(); } } }
public static void DefaultInvtAcctSub(PXGraph graph, INItemSite itemsite, InventoryItem item, INSite site, INPostClass postclass) { if (site != null && site.OverrideInvtAccSub == true) { itemsite.InvtAcctID = site.InvtAcctID; itemsite.InvtSubID = site.InvtSubID; } else if (postclass != null) { itemsite.InvtAcctID = INReleaseProcess.GetAccountDefaults <INPostClass.invtAcctID>(graph, item, site, postclass); itemsite.InvtSubID = INReleaseProcess.GetAccountDefaults <INPostClass.invtSubID>(graph, item, site, postclass); } }
public static void DefaultItemSiteByItem(PXGraph graph, INItemSite itemsite, InventoryItem item, INSite site, INPostClass postclass) { if (item != null) { itemsite.PendingStdCost = item.PendingStdCost; itemsite.PendingStdCostDate = item.PendingStdCostDate; itemsite.StdCost = item.StdCost; itemsite.StdCostDate = item.StdCostDate; itemsite.LastStdCost = item.LastStdCost; itemsite.PendingBasePrice = item.PendingBasePrice; itemsite.PendingBasePriceDate = item.PendingBasePriceDate; itemsite.BasePrice = item.BasePrice; itemsite.BasePriceDate = item.BasePriceDate; itemsite.LastBasePrice = item.LastBasePrice; itemsite.MarkupPct = item.MarkupPct; itemsite.RecPrice = item.RecPrice; itemsite.ABCCodeID = item.ABCCodeID; itemsite.ABCCodeIsFixed = item.ABCCodeIsFixed; itemsite.MovementClassID = item.MovementClassID; itemsite.MovementClassIsFixed = item.MovementClassIsFixed; itemsite.PreferredVendorID = item.PreferredVendorID; itemsite.PreferredVendorLocationID = item.PreferredVendorLocationID; itemsite.ReplenishmentClassID = site != null ? site.ReplenishmentClassID : null; itemsite.DfltReceiptLocationID = site.ReceiptLocationID; itemsite.DfltShipLocationID = site.ShipLocationID; DefaultItemReplenishment(graph, itemsite); DefaultSubItemReplenishment(graph, itemsite); } if (itemsite.InvtAcctID == null) { if (site.OverrideInvtAccSub == true) { itemsite.InvtAcctID = site.InvtAcctID; itemsite.InvtSubID = site.InvtSubID; } else if (postclass != null) { itemsite.InvtAcctID = INReleaseProcess.GetAccountDefaults <INPostClass.invtAcctID>(graph, item, site, postclass); itemsite.InvtSubID = INReleaseProcess.GetAccountDefaults <INPostClass.invtSubID>(graph, item, site, postclass); } itemsite.StdCost = item.StdCost; } }
protected virtual INTran PrepareTransaction(INCostStatus layer, INSite site, InventoryItem inventoryItem, decimal?tranCost) { try { ValidateProjectLocation(site, inventoryItem); } catch (PXException ex) { PXProcessing <INUpdateStdCostRecord> .SetError(ex.Message); return(null); } INTran tran = new INTran(); if (layer.LayerType == INLayerType.Oversold) { tran.TranType = INTranType.NegativeCostAdjustment; } else { tran.TranType = INTranType.StandardCostAdjustment; } tran.BranchID = site.BranchID; tran.InvtAcctID = layer.AccountID; tran.InvtSubID = layer.SubID; var postClass = INPostClass.PK.Find(this, inventoryItem.PostClassID); tran.AcctID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevAcctID> (je, inventoryItem, site, postClass); tran.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevSubID> (je, inventoryItem, site, postClass); tran.InventoryID = layer.InventoryID; tran.SubItemID = layer.CostSubItemID; tran.SiteID = layer.CostSiteID; tran.Qty = 0m; tran.TranCost = tranCost; return(tran); }
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); } }
//Graph passed in function must be the one using newly created sub in details - otherwise save will fail (inserted subs will be created in other graph) protected static void GetLCVarianceAccountSub(ref int?aAccountID, ref int?aSubID, PXGraph aGraph, POReceiptLine aRow) { if (aRow.InventoryID.HasValue) { PXResult <InventoryItem, INPostClass> res = (PXResult <InventoryItem, INPostClass>) PXSelectJoin <InventoryItem, LeftJoin <INPostClass, On <INPostClass.postClassID, Equal <InventoryItem.postClassID> > >, Where <InventoryItem.inventoryID, Equal <Required <POLine.inventoryID> > > > .Select(aGraph, aRow.InventoryID); if (res != null) { InventoryItem invItem = (InventoryItem)res; INPostClass postClass = (INPostClass)res; if ((bool)invItem.StkItem) { if (postClass == null) { throw new PXException(Messages.PostingClassIsNotDefinedForTheItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr); } INSite invSite = null; if (aRow.SiteID != null) { invSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <POReceiptLine.siteID> > > > .Select(aGraph, aRow.SiteID); } if (aRow.LineType == POLineType.GoodsForDropShip) { aAccountID = INReleaseProcess.GetAcctID <INPostClass.cOGSAcctID>(aGraph, postClass.COGSAcctDefault, invItem, invSite, postClass); if (aAccountID == null) { throw new PXException(Messages.COGSAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } try { aSubID = INReleaseProcess.GetSubID <INPostClass.cOGSSubID>(aGraph, postClass.COGSAcctDefault, postClass.COGSSubMask, invItem, invSite, postClass); } catch (PXException ex) { if (postClass.COGSSubID == null || string.IsNullOrEmpty(postClass.COGSSubMask) || invItem.COGSSubID == null || invSite == null || invSite.COGSSubID == null) { throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } else { throw ex; } } if (aSubID == null) { throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } } else { aAccountID = INReleaseProcess.GetAcctID <INPostClass.lCVarianceAcctID>(aGraph, postClass.LCVarianceAcctDefault, invItem, invSite, postClass); if (aAccountID == null) { throw new PXException(Messages.LCVarianceAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } try { aSubID = INReleaseProcess.GetSubID <INPostClass.lCVarianceSubID>(aGraph, postClass.LCVarianceAcctDefault, postClass.LCVarianceSubMask, invItem, invSite, postClass); } catch (PXException ex) { if (postClass.LCVarianceSubID == null || string.IsNullOrEmpty(postClass.LCVarianceSubMask) || invItem.LCVarianceSubID == null || invSite == null || invSite.LCVarianceSubID == null) { throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } else { throw ex; } } if (aSubID == null) { throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, aRow.ReceiptNbr, aRow.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } } } else { aAccountID = aRow.ExpenseAcctID; aSubID = aRow.ExpenseSubID; } } else { throw new PXException(Messages.LCInventoryItemInReceiptRowIsNotFound, aRow.InventoryID, aRow.ReceiptNbr, aRow.LineNbr); } } else { aAccountID = aRow.ExpenseAcctID; aSubID = aRow.ExpenseSubID; } }
public virtual void UpdateStdCost(INUpdateStdCostRecord itemsite) { using (new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { //will be true for non-stock items as well if (itemsite.StdCostOverride == false) { PXDatabase.Update <INItemSite>( new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"), new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate), new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null), new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"), new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID), new PXDataFieldRestrict("StdCostOverride", PXDbType.Bit, false), new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE)); PXDatabase.Update <InventoryItem>( new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"), new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate), new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null), new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"), new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID), new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE)); } else { PXDatabase.Update <INItemSite>( new PXDataFieldAssign("StdCost", PXDbType.DirectExpression, "PendingStdCost"), new PXDataFieldAssign("StdCostDate", PXDbType.DateTime, itemsite.PendingStdCostDate), new PXDataFieldAssign("PendingStdCost", PXDbType.Decimal, 0m), new PXDataFieldAssign("PendingStdCostDate", PXDbType.DateTime, null), new PXDataFieldAssign("LastStdCost", PXDbType.DirectExpression, "StdCost"), new PXDataFieldRestrict("InventoryID", PXDbType.Int, itemsite.InventoryID), new PXDataFieldRestrict("SiteID", PXDbType.Int, itemsite.SiteID), new PXDataFieldRestrict("PendingStdCostDate", PXDbType.DateTime, 4, itemsite.PendingStdCostDate, PXComp.LE)); } if (je.adjustment.Current == null) { je.adjustment.Cache.Insert(); } foreach ( PXResult <INCostStatus, InventoryItem, INSite, INPostClass, INItemSite> res in incoststatus.View.SelectMultiBound(new object[] { je.adjustment.Current, itemsite })) { INCostStatus layer = res; INSite site = res; INTran tran = new INTran(); try { ValidateProjectLocation(site, res); } catch (PXException ex) { PXProcessing <INUpdateStdCostRecord> .SetError(ex.Message); continue; } if (((INCostStatus)res).LayerType == INLayerType.Oversold) { tran.TranType = INTranType.NegativeCostAdjustment; } else { tran.TranType = INTranType.StandardCostAdjustment; } tran.BranchID = site.BranchID; tran.InvtAcctID = layer.AccountID; tran.InvtSubID = layer.SubID; tran.AcctID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevAcctID> (je, (InventoryItem)res, (INSite)res, (INPostClass)res); tran.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.stdCstRevSubID> (je, (InventoryItem)res, (INSite)res, (INPostClass)res); tran.InventoryID = layer.InventoryID; tran.SubItemID = layer.CostSubItemID; tran.SiteID = layer.CostSiteID; tran.Qty = 0m; tran.TranCost = PXDBCurrencyAttribute.BaseRound(this, (decimal)(layer.QtyOnHand * itemsite.PendingStdCost)) - layer.TotalCost; je.transactions.Insert(tran); } if (je.transactions.Select().Count == 0) { je.Clear(); } else { je.Save.Press(); PXProcessing <INUpdateStdCostRecord> .SetInfo(PXMessages.LocalizeFormatNoPrefixNLA(Messages.AdjstmentCreated, je.adjustment.Current.RefNbr)); } ts.Complete(); } } }
protected virtual void GetLCVarianceAccountSub(ref int?aAccountID, ref int?aSubID, POReceiptLine receiptLine) { if (receiptLine.InventoryID.HasValue) { var invItem = InventoryItem.PK.Find(_pxGraph, receiptLine.InventoryID); if (invItem != null) { INPostClass postClass = INPostClass.PK.Find(_pxGraph, invItem.PostClassID); if ((bool)invItem.StkItem) { if (postClass == null) { throw new PXException(Messages.PostingClassIsNotDefinedForTheItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr); } INSite invSite = null; if (receiptLine.SiteID != null) { invSite = INSite.PK.Find(_pxGraph, receiptLine.SiteID); } if (receiptLine.LineType == POLineType.GoodsForDropShip) { aAccountID = INReleaseProcess.GetAcctID <INPostClass.cOGSAcctID>(_pxGraph, postClass.COGSAcctDefault, invItem, invSite, postClass); if (aAccountID == null) { throw new PXException(Messages.COGSAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } try { aSubID = INReleaseProcess.GetSubID <INPostClass.cOGSSubID>(_pxGraph, postClass.COGSAcctDefault, postClass.COGSSubMask, invItem, invSite, postClass); } catch (PXException ex) { if (postClass.COGSSubID == null || string.IsNullOrEmpty(postClass.COGSSubMask) || invItem.COGSSubID == null || invSite == null || invSite.COGSSubID == null) { throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } else { throw ex; } } if (aSubID == null) { throw new PXException(Messages.COGSSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } } else { aAccountID = INReleaseProcess.GetAcctID <INPostClass.lCVarianceAcctID>(_pxGraph, postClass.LCVarianceAcctDefault, invItem, invSite, postClass); if (aAccountID == null) { throw new PXException(Messages.LCVarianceAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } try { aSubID = INReleaseProcess.GetSubID <INPostClass.lCVarianceSubID>(_pxGraph, postClass.LCVarianceAcctDefault, postClass.LCVarianceSubMask, invItem, invSite, postClass); } catch (PXException ex) { if (postClass.LCVarianceSubID == null || string.IsNullOrEmpty(postClass.LCVarianceSubMask) || invItem.LCVarianceSubID == null || invSite == null || invSite.LCVarianceSubID == null) { throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } else { throw ex; } } if (aSubID == null) { throw new PXException(Messages.LCVarianceSubAccountCanNotBeFoundForItemInReceiptRow, invItem.InventoryCD, receiptLine.ReceiptNbr, receiptLine.LineNbr, postClass.PostClassID, invSite != null ? invSite.SiteCD : String.Empty); } } } else { aAccountID = receiptLine.ExpenseAcctID; aSubID = receiptLine.ExpenseSubID; } } else { throw new PXException(Messages.LCInventoryItemInReceiptRowIsNotFound, receiptLine.InventoryID, receiptLine.ReceiptNbr, receiptLine.LineNbr); } } else { aAccountID = receiptLine.ExpenseAcctID; aSubID = receiptLine.ExpenseSubID; } }
public virtual bool HandleARTranCost(ARTran n, ARInvoice ardoc, JournalEntry je) { if (n.LineType.IsNotIn(SOLineType.Inventory, SOLineType.NonInventory)) { return(false); } bool tranCostSet = false; n.TranCost = 0m; foreach (INTran intran in this.intranselect.View.SelectMultiBound(new object[] { n })) { intran.ARDocType = n.TranType; intran.ARRefNbr = n.RefNbr; intran.ARLineNbr = n.LineNbr; intran.UnitPrice = n.UnitPrice; intran.TranAmt = Math.Sign((decimal)n.Qty) != Math.Sign((decimal)n.BaseQty) ? -n.TranAmt : n.TranAmt; if (n.Qty != 0m && n.SOShipmentLineNbr == null) { object TranAmt = Math.Sign((decimal)n.Qty) != Math.Sign((decimal)n.BaseQty) ? -n.TranAmt : n.TranAmt / n.Qty * intran.Qty; this.intranselect.Cache.RaiseFieldUpdating <INTran.tranAmt>(intran, ref TranAmt); intran.TranAmt = (decimal?)TranAmt; } this.intranselect.Cache.MarkUpdated(intran); if (intran.Released == true) { INReleaseProcess.UpdateCustSalesStats(Base, intran); var initem = InventoryItem.PK.Find(Base, n.InventoryID); if (initem != null && initem.StkItem != true && initem.KitItem == true && PXAccess.FeatureInstalled <FeaturesSet.kitAssemblies>() && this.SOSetup.Current != null) { switch (this.SOSetup.Current.SalesProfitabilityForNSKits) { case SalesProfitabilityNSKitMethod.NSKitStandardCostOnly: //do nothing break; case SalesProfitabilityNSKitMethod.NSKitStandardAndStockComponentsCost: //kit standard cost will be added later n.TranCost += intran.TranCost; n.TranCostOrig = n.TranCost; n.IsTranCostFinal = true; break; case SalesProfitabilityNSKitMethod.StockComponentsCostOnly: n.TranCost += intran.TranCost; n.TranCostOrig = n.TranCost; n.IsTranCostFinal = true; tranCostSet = true; break; } } else { n.TranCost += intran.TranCost; n.TranCostOrig = n.TranCost; n.IsTranCostFinal = true; tranCostSet = true; } } PostShippedNotInvoiced(intran, n, ardoc, je); } if (n.SOShipmentType == SO.SOShipmentType.DropShip) { foreach (INTran intran in PXSelect <INTran, Where <INTran.pOReceiptNbr, Equal <Current <ARTran.sOShipmentNbr> >, And <INTran.pOReceiptLineNbr, Equal <Current <ARTran.sOShipmentLineNbr> >, And <INTran.docType, Equal <IN.INDocType.adjustment>, And <INTran.released, Equal <True>, And <INTran.aRRefNbr, IsNull, And <INTran.sOShipmentNbr, IsNull> > > > > > > .SelectMultiBound(Base, new object[] { n })) { n.TranCost += intran.TranCost; } } return(tranCostSet); }
public virtual void PostShippedNotInvoiced(INTran intran, ARTran n, ARInvoice ardoc, JournalEntry je) { if (intran.UpdateShippedNotInvoiced != true) { return; } if (intran.Released != true) { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(AR.Messages.ShippedNotInvoicedINtranNotReleased, intran.RefNbr)); } var trancosts = PXSelect <INTranCost, Where <INTranCost.costDocType, Equal <Required <INTranCost.costDocType> >, And <INTranCost.costRefNbr, Equal <Required <INTranCost.costRefNbr> >, And <INTranCost.lineNbr, Equal <Required <INTranCost.lineNbr> > > > > > .Select(Base, intran.DocType, intran.RefNbr, intran.LineNbr); foreach (INTranCost trancost in trancosts) { var itemPostClassRes = (PXResult <InventoryItem, INPostClass>) PXSelectJoin <InventoryItem, LeftJoin <INPostClass, On <INPostClass.postClassID, Equal <InventoryItem.postClassID> > >, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(Base, intran.InventoryID); ReasonCode reasoncode = INTran.FK.ReasonCode.FindParent(Base, intran); INSite site = INSite.PK.Find(Base, intran.SiteID); if (trancost != null && trancost.COGSAcctID != null && intran != null) { //Credit shipped-not-invoiced account GLTran tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = intran.BranchID; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.AccountID = intran.COGSAcctID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.SubID = intran.COGSSubID ?? INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes, intran); tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? trancost.Qty : -trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; bool isNonProject = trancost.InvtMult == (short)0; tranFromIN.ProjectID = isNonProject ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = isNonProject ? null : intran.TaskID; tranFromIN.CostCodeID = tranFromIN.CostCodeID; tranFromIN.Released = true; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); //Debit COGS account tranFromIN = new GLTran(); tranFromIN.SummPost = Base.SummPost; tranFromIN.BranchID = n.BranchID; if (reasoncode?.Usage == ReasonCodeUsages.Issue) { tranFromIN.AccountID = reasoncode.AccountID; tranFromIN.SubID = INReleaseProcess.GetReasonCodeSubID(Base, reasoncode, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.AccountID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSAcctID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); if (((INPostClass)itemPostClassRes) != null && ((INPostClass)itemPostClassRes).COGSSubFromSales != true) //we cannot use intran here to retrive cogs/sales sub { tranFromIN.SubID = INReleaseProcess.GetAccountDefaults <INPostClass.cOGSSubID>(Base, (InventoryItem)itemPostClassRes, site, (INPostClass)itemPostClassRes); } else { tranFromIN.SubID = n.SubID; } } tranFromIN.CuryDebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.DebitAmt = (trancost.InvtMult == (short)1) ? 0m : trancost.TranCost; tranFromIN.CuryCreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.CreditAmt = (trancost.InvtMult == (short)1) ? trancost.TranCost : 0m; tranFromIN.TranType = trancost.TranType; tranFromIN.TranClass = GLTran.tranClass.ShippedNotInvoiced; tranFromIN.RefNbr = trancost.RefNbr; tranFromIN.InventoryID = trancost.InventoryID; tranFromIN.Qty = (trancost.InvtMult == (short)1) ? -trancost.Qty : trancost.Qty; tranFromIN.UOM = intran.UOM; tranFromIN.TranDesc = intran.TranDesc; tranFromIN.TranDate = n.TranDate; tranFromIN.ProjectID = (trancost.InvtMult == (short)1) ? PM.ProjectDefaultAttribute.NonProject() : intran.ProjectID; tranFromIN.TaskID = (trancost.InvtMult == (short)1) ? null : intran.TaskID; tranFromIN.CostCodeID = intran.CostCodeID; tranFromIN.Released = true; tranFromIN.TranLineNbr = (tranFromIN.SummPost == true) ? null : intran.LineNbr; Base.InsertInvoiceDetailsINTranCostTransaction(je, tranFromIN, new GLTranInsertionContext { ARRegisterRecord = ardoc, ARTranRecord = n, INTranRecord = intran, INTranCostRecord = trancost }); } } }