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 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(); } } }
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 }); } } }