public virtual void CopySOLine() { SOLineSplitFilter current1 = this.LineSplitFilter.Current; SOLine current2 = this.Base.Transactions.Current; SOLine copy = this.Base.Transactions.Cache.CreateCopy((object)current2) as SOLine; copy.LineNbr = copy.SortOrder = (int?)PXLineNbrAttribute.NewLineNbr <SOLine.lineNbr>(this.Base.Transactions.Cache, (object)this.Base.Document.Current); SOLine soLine1 = copy; DateTime?shipDate = current1.ShipDate; DateTime?nullable1 = shipDate.HasValue ? shipDate : current2.ShipDate; soLine1.ShipDate = nullable1; SOLine soLine2 = copy; bool? poCreate = current2.POCreate; bool flag = true; bool? nullable2 = poCreate.GetValueOrDefault() == flag & poCreate.HasValue ? new bool?(!this.SOSplitHasPONbr(current2)) : current2.POCreate; soLine2.POCreate = nullable2; copy.NoteID = new Guid?(Guid.NewGuid()); copy.GetExtension <SOLineExt>().UsrOrigQty = current1.SplitQty; this.Base.Transactions.Insert(copy); copy.OrderQty = current1.SplitQty; this.Base.Transactions.Update(copy); if (!current2.GetExtension <SOLineExt>().UsrOrigQty.HasValue) { current2.GetExtension <SOLineExt>().UsrOrigQty = current2.OrderQty; } SOLine soLine3 = current2; Decimal?orderQty = soLine3.OrderQty; Decimal?qty = copy.Qty; soLine3.OrderQty = orderQty.HasValue & qty.HasValue ? new Decimal?(orderQty.GetValueOrDefault() - qty.GetValueOrDefault()) : new Decimal?(); this.Base.Transactions.Update(current2); }
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); } } } }
protected void ReceiptDetails_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity) { var lineNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "OrigLineNbr") as EntityValueField; var receiptQty = targetEntity.Fields.SingleOrDefault(f => f.Name == "Quantity") as EntityValueField; var location = targetEntity.Fields.SingleOrDefault(f => f.Name == "Location") as EntityValueField; var allocations = (targetEntity.Fields.SingleOrDefault(f => string.Equals(f.Name, "Allocations")) as EntityListField).Value ?? new EntityImpl[0]; var hasAllocations = allocations.Any(a => a.Fields != null && a.Fields.Length > 0); var receiptEntry = (INReceiptEntry)graph; string transferNbr = receiptEntry.receipt.Current.TransferNbr; var detailsCache = receiptEntry.transactions.Cache; if (lineNbr == null || transferNbr == null) { detailsCache.Current = detailsCache.Insert(); return; } INTran newtran = null; decimal newtranqty = Decimal.Parse(receiptQty.Value); decimal newtrancost = 0m; receiptEntry.ParseSubItemSegKeys(); using (new PXReadBranchRestrictedScope()) { foreach (PXResult <INTransitLine, INLocationStatus2, INTransitLineLotSerialStatus, INSite, InventoryItem, INTran> res in PXSelectJoin <INTransitLine, InnerJoin <INLocationStatus2, On <INLocationStatus2.locationID, Equal <INTransitLine.costSiteID> >, LeftJoin <INTransitLineLotSerialStatus, On <INTransitLine.transferNbr, Equal <INTransitLineLotSerialStatus.transferNbr>, And <INTransitLine.transferLineNbr, Equal <INTransitLineLotSerialStatus.transferLineNbr> > >, InnerJoin <INSite, On <INSite.siteID, Equal <INTransitLine.toSiteID> >, InnerJoin <InventoryItem, On <InventoryItem.inventoryID, Equal <INLocationStatus2.inventoryID> >, InnerJoin <INTran, On <INTran.docType, Equal <INDocType.transfer>, And <INTran.refNbr, Equal <INTransitLine.transferNbr>, And <INTran.lineNbr, Equal <INTransitLine.transferLineNbr>, And <INTran.invtMult, Equal <shortMinus1> > > > > > > > > >, Where <INTransitLine.transferNbr, Equal <Required <INTransitLine.transferNbr> >, And <INTransitLine.transferLineNbr, Equal <Required <INTransitLine.transferLineNbr> > > >, OrderBy <Asc <INTransitLine.transferNbr, Asc <INTransitLine.transferLineNbr> > > > .Select(receiptEntry, transferNbr, lineNbr.Value)) { INTransitLine transitline = res; INLocationStatus2 stat = res; INTransitLineLotSerialStatus lotstat = res; INSite site = res; InventoryItem item = res; INTran tran = res; if (stat.QtyOnHand == 0m || (lotstat != null && lotstat.QtyOnHand == 0m)) { continue; } if (newtran == null) { if (!object.Equals(receiptEntry.receipt.Current.BranchID, site.BranchID)) { INRegister copy = PXCache <INRegister> .CreateCopy(receiptEntry.receipt.Current); copy.BranchID = site.BranchID; receiptEntry.receipt.Update(copy); } newtran = PXCache <INTran> .CreateCopy(tran); newtran.OrigBranchID = newtran.BranchID; newtran.OrigTranType = newtran.TranType; newtran.OrigRefNbr = transitline.TransferNbr; newtran.OrigLineNbr = transitline.TransferLineNbr; newtran.BranchID = site.BranchID; newtran.DocType = receiptEntry.receipt.Current.DocType; newtran.RefNbr = receiptEntry.receipt.Current.RefNbr; newtran.LineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTran.lineNbr>(receiptEntry.transactions.Cache, receiptEntry.receipt.Current); newtran.InvtMult = (short)1; newtran.SiteID = transitline.ToSiteID; newtran.LocationID = transitline.ToLocationID; newtran.ToSiteID = null; newtran.ToLocationID = null; newtran.BaseQty = 0m; newtran.Qty = 0m; newtran.UnitCost = 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; newtran.CostCodeID = null; newtran.TranCost = 0m; receiptEntry.splits.Current = null; newtran = receiptEntry.transactions.Insert(newtran); receiptEntry.transactions.Current = newtran; if (receiptEntry.splits.Current != null) { receiptEntry.splits.Delete(receiptEntry.splits.Current); } } if (hasAllocations) { newtranqty = 0m; foreach (var allocation in allocations) { var newsplitqty = allocation.Fields.SingleOrDefault(f => f.Name == "Quantity") as EntityValueField; var newsplitlocation = allocation.Fields.SingleOrDefault(f => f.Name == "Location") as EntityValueField; INTranSplit newsplit = this.addReceiptSplitLine(receiptEntry, stat, lotstat, transitline, newtran, item, Decimal.Parse(newsplitqty.Value), newsplitlocation.Value); newtrancost += newsplit.BaseQty.Value * newsplit.UnitCost.Value; newtranqty += newsplit.BaseQty.Value; } break; } else { INTranSplit newsplit = this.addReceiptSplitLine(receiptEntry, stat, lotstat, transitline, tran, item, newtranqty, null); newtrancost += newsplit.BaseQty.Value * newsplit.UnitCost.Value; newtranqty += newsplit.BaseQty.Value; } } receiptEntry.UpdateTranCostQty(newtran, newtranqty, newtrancost); } }
private INTranSplit addReceiptSplitLine(INReceiptEntry receiptEntry, INLocationStatus2 stat, INTransitLineLotSerialStatus lotstat, INTransitLine transitline, INTran tran, InventoryItem item, Decimal qty, string location) { INTranSplit newsplit; decimal newsplitqty; if (lotstat.QtyOnHand == null) { newsplit = new INTranSplit(); newsplit.InventoryID = stat.InventoryID; newsplit.IsStockItem = true; newsplit.FromSiteID = transitline.SiteID; newsplit.SubItemID = stat.SubItemID; newsplit.LotSerialNbr = null; newsplitqty = qty; } else { newsplit = new INTranSplit(); newsplit.InventoryID = lotstat.InventoryID; newsplit.IsStockItem = true; newsplit.FromSiteID = lotstat.FromSiteID; newsplit.SubItemID = lotstat.SubItemID; newsplit.LotSerialNbr = lotstat.LotSerialNbr; newsplitqty = qty; } newsplit.DocType = receiptEntry.receipt.Current.DocType; newsplit.RefNbr = receiptEntry.receipt.Current.RefNbr; newsplit.LineNbr = tran.LineNbr; newsplit.SplitLineNbr = (int)PXLineNbrAttribute.NewLineNbr <INTranSplit.splitLineNbr>(receiptEntry.splits.Cache, receiptEntry.receipt.Current); newsplit.UnitCost = 0m; newsplit.InvtMult = (short)1; newsplit.SiteID = transitline.ToSiteID; newsplit.PlanID = null; newsplit.Released = false; newsplit.ProjectID = null; newsplit.TaskID = null; if (location == null) { newsplit.LocationID = lotstat.ToLocationID ?? transitline.ToLocationID; } else { receiptEntry.splits.SetValueExt <INTranSplit.locationID>(newsplit, location); } newsplit = receiptEntry.splits.Insert(newsplit); newsplit.MaxTransferBaseQty = newsplitqty; newsplit.BaseQty = newsplitqty; newsplit.Qty = newsplit.BaseQty.Value; receiptEntry.UpdateCostSubItemID(newsplit, item); receiptEntry.SetCostAttributes(tran, newsplit, item, tran.OrigRefNbr); newsplit.UnitCost = PXCurrencyAttribute.BaseRound(receiptEntry, newsplit.UnitCost); receiptEntry.splits.Update(newsplit); return(newsplit); }