protected virtual bool TryCalcPlanType(INItemPlan plan, bool isOnHold, out string newPlanType) { newPlanType = null; switch (plan.PlanType) { case INPlanConstants.PlanM3: case INPlanConstants.PlanM4: newPlanType = isOnHold ? INPlanConstants.PlanM3 : INPlanConstants.PlanM4; break; case INPlanConstants.Plan70: case INPlanConstants.Plan73: newPlanType = isOnHold ? INPlanConstants.Plan73 : INPlanConstants.Plan70; break; case INPlanConstants.Plan76: case INPlanConstants.Plan78: newPlanType = isOnHold ? INPlanConstants.Plan78 : INPlanConstants.Plan76; break; case INPlanConstants.Plan74: case INPlanConstants.Plan79: newPlanType = isOnHold ? INPlanConstants.Plan79 : INPlanConstants.Plan74; break; case INPlanConstants.PlanF7: case INPlanConstants.PlanF8: newPlanType = isOnHold ? INPlanConstants.PlanF8 : INPlanConstants.PlanF7; break; } return(newPlanType != null); }
public override INItemPlan DefaultValues(PXCache sender, INItemPlan plan_Row, object origRow) { ARTran tran = (ARTran)origRow; if (tran.Released == true || tran.SOShipmentNbr != null || tran.SOOrderNbr != null || tran.LineType != SOLineType.Inventory || tran.InvtMult == 0) { return(null); } PXCache cache = sender.Graph.Caches[BqlCommand.GetItemType(_ParentNoteID)]; bool? hold = (bool?)cache.GetValue(cache.Current, _ParentHoldEntry.Name) | (bool?)cache.GetValue <ARInvoice.creditHold>(cache.Current); plan_Row.BAccountID = tran.CustomerID; plan_Row.PlanType = (hold == true) ? INPlanConstants.Plan69 : INPlanConstants.Plan62; plan_Row.InventoryID = tran.InventoryID; plan_Row.SubItemID = tran.SubItemID; plan_Row.SiteID = tran.SiteID; plan_Row.LocationID = tran.LocationID; plan_Row.LotSerialNbr = tran.LotSerialNbr; plan_Row.Reverse = (tran.InvtMult > 0) ^ (tran.BaseQty < 0m); plan_Row.PlanDate = (DateTime?)cache.GetValue <ARRegister.docDate>(cache.Current); plan_Row.PlanQty = Math.Abs(tran.BaseQty ?? 0m); plan_Row.RefNoteID = (Guid?)cache.GetValue(cache.Current, _ParentNoteID.Name); plan_Row.Hold = hold; return(plan_Row); }
public DocLineExt(PXResult <FSAppointmentInventoryItem, FSAppointment, FSServiceOrder, FSSrvOrdType, FSPostDoc, FSPostInfo, INItemPlan> appointmentDetLine) { this.docLine = (IDocLine)(FSAppointmentInventoryItem)appointmentDetLine; this.fsPostDoc = (FSPostDoc)appointmentDetLine; this.fsServiceOrder = (FSServiceOrder)appointmentDetLine; this.fsSrvOrdType = (FSSrvOrdType)appointmentDetLine; this.fsAppointment = (FSAppointment)appointmentDetLine; this.fsPostInfo = (FSPostInfo)appointmentDetLine; this.fsSODet = null; this.fsSODetSplit = null; this.inItemPlan = (INItemPlan)appointmentDetLine; }
public DocLineExt(PXResult <FSSODet, FSServiceOrder, FSSrvOrdType, FSSODetSplit, INItemPlan> soDetLine) { this.docLine = (IDocLine)(FSSODet)soDetLine; this.fsPostDoc = null; this.fsServiceOrder = (FSServiceOrder)soDetLine; this.fsSrvOrdType = (FSSrvOrdType)soDetLine; this.fsAppointment = null; this.fsPostInfo = null; this.fsSODet = (FSSODet)soDetLine; this.fsSODetSplit = (FSSODetSplit)soDetLine; this.inItemPlan = (INItemPlan)soDetLine; }
public DocLineExt(PXResult <FSAppointmentDet, FSAppointment, FSServiceOrder, FSSrvOrdType, FSPostDoc, FSPostInfo, PMTask> appointmentDetLine) { this.docLine = (IDocLine)(FSAppointmentDet)appointmentDetLine; this.fsPostDoc = (FSPostDoc)appointmentDetLine; this.fsServiceOrder = (FSServiceOrder)appointmentDetLine; this.fsSrvOrdType = (FSSrvOrdType)appointmentDetLine; this.fsAppointment = (FSAppointment)appointmentDetLine; this.fsPostInfo = (FSPostInfo)appointmentDetLine; this.fsSODet = null; this.fsSODetSplit = null; this.inItemPlan = null; this.pmTask = (PMTask)appointmentDetLine; }
public override INItemPlan DefaultValues(PXCache sender, INItemPlan plan_Row, object orig_Row) { string orderType = (string)sender.GetValue <POLine.orderType>(orig_Row); string orderNbr = (string)sender.GetValue <POLine.orderNbr>(orig_Row); int? inventoryID = (int?)sender.GetValue <POLine.inventoryID>(orig_Row); int? siteID = (int?)sender.GetValue <POLine.siteID>(orig_Row); bool? cancelled = (bool?)sender.GetValue <POLine.cancelled>(orig_Row); bool? completed = (bool?)sender.GetValue <POLine.completed>(orig_Row); if (orderType.IsNotIn(POOrderType.RegularOrder, POOrderType.DropShip, POOrderType.Blanket) || inventoryID == null || siteID == null || cancelled == true || completed == true) { return(null); } PXCache parentCache = sender.Graph.Caches[BqlCommand.GetItemType(_ParentNoteID)]; POOrder currentOrder = (POOrder)parentCache.Current; POOrder order = currentOrder?.OrderType == orderType && currentOrder.OrderNbr == orderNbr ? currentOrder : (POOrder)PXParentAttribute.SelectParent(sender, orig_Row, typeof(POOrder));; bool IsOnHold = IsOrderOnHold(order); string newPlanType; if (!TryCalcPlanType(sender, orig_Row, IsOnHold, out newPlanType)) { return(null); } plan_Row.PlanType = newPlanType; plan_Row.BAccountID = (int?)sender.GetValue <POLine.vendorID>(orig_Row); plan_Row.InventoryID = inventoryID; plan_Row.SubItemID = (int?)sender.GetValue <POLine.subItemID>(orig_Row); plan_Row.SiteID = siteID; plan_Row.PlanDate = (DateTime?)sender.GetValue <POLine.promisedDate>(orig_Row); plan_Row.PlanQty = (decimal?)sender.GetValue <POLine.baseOpenQty>(orig_Row); plan_Row.RefNoteID = (Guid?)parentCache.GetValue(order, _ParentNoteID.Name); plan_Row.Hold = IsOnHold; if (string.IsNullOrEmpty(plan_Row.PlanType)) { return(null); } return(plan_Row); }
public virtual void Copy(POReceiptLine aDest, POLine aSrc, decimal aQtyAdj, decimal aBaseQtyAdj, CopyOrig del) { if (del != null) { del(aDest, aSrc, aQtyAdj, aBaseQtyAdj); } INItemPlan inItemPlanRow = PXSelect <INItemPlan, Where < INItemPlan.supplyPlanID, Equal <Required <INItemPlan.supplyPlanID> >, And <INItemPlan.planType, Equal <Required <INItemPlan.planType> > > > > .Select(Base, aSrc.PlanID, INPlanConstants.PlanF6); if (inItemPlanRow != null && inItemPlanRow.LocationID != null) { aDest.LocationID = inItemPlanRow.LocationID; } }
public override void Parent_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { base.Parent_RowUpdated(sender, e); if (!sender.ObjectsEqual <POOrder.status, POOrder.cancelled>(e.Row, e.OldRow) || //There are two graphs when automation step with notification is getting applied. One of them (the one made by automation) will be //persisted, while another one is only displayed on the screen. Due to cache sharing and because of automatic screen refresh //we will get the same Status in e.Row and e.OldRow while in fact they are different (example - transition from NL Pending Email to NL Open step) (sender.Graph.UnattendedMode && (sender.Graph.AutomationStep != sender.Graph.AutomationStepOriginal))) { POOrder order = (POOrder)e.Row; PXCache plancache = sender.Graph.Caches[typeof(INItemPlan)]; bool Cancelled = (bool?)sender.GetValue <POOrder.cancelled>(e.Row) == true; foreach (INItemPlan plan in PXSelect <INItemPlan, Where <INItemPlan.refNoteID, Equal <Current <POOrder.noteID> > > > .Select(sender.Graph)) { if (Cancelled) { plancache.Delete(plan); } else { INItemPlan copy = PXCache <INItemPlan> .CreateCopy(plan); bool IsOnHold = IsOrderOnHold(order); string newPlanType; if (TryCalcPlanType(plan, IsOnHold, out newPlanType)) { plan.PlanType = newPlanType; } plan.Hold = IsOnHold; if (!string.Equals(copy.PlanType, plan.PlanType)) { plancache.RaiseRowUpdated(plan, copy); } plancache.MarkUpdated(plan); } } } }
private static void UpdateSchedulesFromCompletedPO(PXGraph graph, PXSelect <FSSODetSplit> fsSODetSplit, PXSelect <INItemPlan> initemplan, FSSODetSplit parentschedule, PXSelect <FSServiceOrder> fsServiceOrder, INItemPlan demand) { graph.FieldDefaulting.AddHandler <FSSODetSplit.locationID>((sender, e) => { if (e.Row != null && ((FSSODetSplit)e.Row).RequireLocation != true) { e.NewValue = null; e.Cancel = true; } }); FSSODetSplit newschedule = PXCache <FSSODetSplit> .CreateCopy(parentschedule); ClearScheduleReferences(ref newschedule); newschedule.LotSerialNbr = demand.LotSerialNbr; newschedule.SiteID = demand.SiteID; newschedule.BaseQty = parentschedule.BaseQty - parentschedule.BaseReceivedQty; newschedule.Qty = INUnitAttribute.ConvertFromBase(fsSODetSplit.Cache, newschedule.InventoryID, newschedule.UOM, (decimal)newschedule.BaseQty, INPrecision.QUANTITY); newschedule.BaseReceivedQty = 0m; newschedule.ReceivedQty = 0m; //creating new plan INItemPlan newPlan = PXCache <INItemPlan> .CreateCopy(demand); newPlan.PlanID = null; newPlan.SupplyPlanID = null; newPlan.DemandPlanID = null; newPlan.PlanQty = newschedule.BaseQty; newPlan.VendorID = null; newPlan.VendorLocationID = null; newPlan.FixedSource = INReplenishmentSource.None; newPlan.PlanType = (fsServiceOrder.Current != null && fsServiceOrder.Current.Hold == true) ? INPlanConstants.Plan69 : INPlanConstants.Plan60; newPlan = (INItemPlan)initemplan.Cache.Insert(newPlan); newschedule.PlanID = newPlan.PlanID; fsSODetSplit.Cache.Insert(newschedule); }
public List <PXResult <INItemPlan, INPlanType> > ProcessPOReceipt(PXGraph graph, IEnumerable <PXResult <INItemPlan, INPlanType> > list, string POReceiptType, string POReceiptNbr) { var serviceOrder = new PXSelect <FSServiceOrder>(graph); if (!graph.Views.Caches.Contains(typeof(FSServiceOrder))) { graph.Views.Caches.Add(typeof(FSServiceOrder)); } var soDetSplit = new PXSelect <FSSODetSplit>(graph); if (!graph.Views.Caches.Contains(typeof(FSSODetSplit))) { graph.Views.Caches.Add(typeof(FSSODetSplit)); } var initemplan = new PXSelect <INItemPlan>(graph); List <PXResult <INItemPlan, INPlanType> > returnList = new List <PXResult <INItemPlan, INPlanType> >(); Base.FieldVerifying.AddHandler <FSSODetSplit.lotSerialNbr>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; }); List <FSSODetSplit> splitsToDeletePlanID = new List <FSSODetSplit>(); List <FSSODetSplit> insertedSchedules = new List <FSSODetSplit>(); List <INItemPlan> deletedPlans = new List <INItemPlan>(); foreach (PXResult <INItemPlan, INPlanType> res in list) { bool includeInReturnList = true; INItemPlan plan = PXCache <INItemPlan> .CreateCopy(res); INPlanType plantype = res; //avoid ReadItem() if (initemplan.Cache.GetStatus(plan) != PXEntryStatus.Inserted) { initemplan.Cache.SetStatus(plan, PXEntryStatus.Notchanged); } //Original Schedule Marked for PO / Allocated on Remote Whse //FSSODetSplit schedule = PXSelect<FSSODetSplit, Where<FSSODetSplit.planID, Equal<Required<FSSODetSplit.planID>>, And<FSSODetSplit.completed, Equal<False>>>>.Select(this, plan.DemandPlanID); FSSODetSplit schedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.planID, Equal <Required <FSSODetSplit.planID> > > > .Select(graph, plan.DemandPlanID); if (schedule != null && (schedule.Completed == false || soDetSplit.Cache.GetStatus(schedule) == PXEntryStatus.Updated)) { includeInReturnList = false; schedule = PXCache <FSSODetSplit> .CreateCopy(schedule); schedule.BaseReceivedQty += plan.PlanQty; schedule.ReceivedQty = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseReceivedQty, INPrecision.QUANTITY); soDetSplit.Cache.Update(schedule); INItemPlan origplan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .Select(graph, plan.DemandPlanID); if (origplan != null) { origplan.PlanQty = schedule.BaseQty - schedule.BaseReceivedQty; initemplan.Cache.Update(origplan); } //select Allocated line if any, exclude allocated on Remote Whse PXSelectBase <INItemPlan> cmd = new PXSelectJoin <INItemPlan, InnerJoin <FSSODetSplit, On <FSSODetSplit.planID, Equal <INItemPlan.planID> > >, Where <INItemPlan.demandPlanID, Equal <Required <INItemPlan.demandPlanID> >, And <FSSODetSplit.isAllocated, Equal <True>, And <FSSODetSplit.siteID, Equal <Required <FSSODetSplit.siteID> > > > > >(graph); if (!string.IsNullOrEmpty(plan.LotSerialNbr)) { cmd.WhereAnd <Where <INItemPlan.lotSerialNbr, Equal <Required <INItemPlan.lotSerialNbr> > > >(); } PXResult <INItemPlan> allocres = cmd.Select(plan.DemandPlanID, plan.SiteID, plan.LotSerialNbr); if (allocres != null) { schedule = PXResult.Unwrap <FSSODetSplit>(allocres); soDetSplit.Cache.SetStatus(schedule, PXEntryStatus.Notchanged); schedule = PXCache <FSSODetSplit> .CreateCopy(schedule); schedule.BaseQty += plan.PlanQty; schedule.Qty = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseQty, INPrecision.QUANTITY); schedule.POReceiptType = POReceiptType; schedule.POReceiptNbr = POReceiptNbr; soDetSplit.Cache.Update(schedule); INItemPlan allocplan = PXCache <INItemPlan> .CreateCopy(res); allocplan.PlanQty += plan.PlanQty; initemplan.Cache.Update(allocplan); plantype = PXCache <INPlanType> .CreateCopy(plantype); plantype.ReplanOnEvent = null; plantype.DeleteOnEvent = true; } else { serviceOrder.Current = (FSServiceOrder)PXParentAttribute.SelectParent(soDetSplit.Cache, schedule, typeof(FSServiceOrder)); schedule = PXCache <FSSODetSplit> .CreateCopy(schedule); long?oldPlanID = schedule.PlanID; ClearScheduleReferences(ref schedule); plantype.ReplanOnEvent = INPlanConstants.PlanF1; schedule.IsAllocated = false; schedule.LotSerialNbr = plan.LotSerialNbr; schedule.POCreate = false; schedule.POSource = null; schedule.POReceiptType = POReceiptType; schedule.POReceiptNbr = POReceiptNbr; schedule.SiteID = plan.SiteID; schedule.VendorID = null; schedule.BaseReceivedQty = 0m; schedule.ReceivedQty = 0m; schedule.BaseQty = plan.PlanQty; schedule.Qty = INUnitAttribute.ConvertFromBase(soDetSplit.Cache, schedule.InventoryID, schedule.UOM, (decimal)schedule.BaseQty, INPrecision.QUANTITY); //update SupplyPlanID in existing item plans (replenishment) foreach (PXResult <INItemPlan> demand_res in PXSelect <INItemPlan, Where <INItemPlan.supplyPlanID, Equal <Required <INItemPlan.supplyPlanID> > > > .Select(graph, oldPlanID)) { INItemPlan demand_plan = PXCache <INItemPlan> .CreateCopy(demand_res); initemplan.Cache.SetStatus(demand_plan, PXEntryStatus.Notchanged); demand_plan.SupplyPlanID = plan.PlanID; initemplan.Cache.Update(demand_plan); } schedule.PlanID = plan.PlanID; schedule = (FSSODetSplit)soDetSplit.Cache.Insert(schedule); insertedSchedules.Add(schedule); } } else if (plan.DemandPlanID == null) { //Original schedule Marked for PO //TODO: verify this is sufficient for Original SO marked for TR. schedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.planID, Equal <Required <FSSODetSplit.planID> >, And <FSSODetSplit.completed, Equal <False> > > > .Select(graph, plan.PlanID); if (schedule != null) { includeInReturnList = false; soDetSplit.Cache.SetStatus(schedule, PXEntryStatus.Notchanged); schedule = PXCache <FSSODetSplit> .CreateCopy(schedule); schedule.Completed = true; schedule.POCompleted = true; splitsToDeletePlanID.Add(schedule); soDetSplit.Cache.Update(schedule); INItemPlan origplan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .Select(graph, plan.PlanID); deletedPlans.Add(origplan); initemplan.Cache.Delete(origplan); } } if (includeInReturnList == true) { returnList.Add(res); } else { if (plantype.ReplanOnEvent != null) { plan.PlanType = plantype.ReplanOnEvent; plan.SupplyPlanID = null; plan.DemandPlanID = null; initemplan.Cache.Update(plan); } else if (plantype.DeleteOnEvent == true) { initemplan.Delete(plan); } } } //Create new schedules for partially received schedules marked for PO. FSSODetSplit prevSplit = null; foreach (FSSODetSplit newsplit in insertedSchedules) { if (prevSplit != null && prevSplit.SrvOrdType == newsplit.SrvOrdType && prevSplit.RefNbr == newsplit.RefNbr && prevSplit.LineNbr == newsplit.LineNbr && prevSplit.InventoryID == newsplit.InventoryID && prevSplit.SubItemID == newsplit.SubItemID && prevSplit.ParentSplitLineNbr == newsplit.ParentSplitLineNbr && prevSplit.LotSerialNbr != null && newsplit.LotSerialNbr != null) { continue; } FSSODetSplit parentschedule = PXSelect <FSSODetSplit, Where <FSSODetSplit.srvOrdType, Equal <Required <FSSODetSplit.srvOrdType> >, And <FSSODetSplit.refNbr, Equal <Required <FSSODetSplit.refNbr> >, And <FSSODetSplit.lineNbr, Equal <Required <FSSODetSplit.lineNbr> >, And <FSSODetSplit.splitLineNbr, Equal <Required <FSSODetSplit.parentSplitLineNbr> > > > > > > .Select(graph, newsplit.SrvOrdType, newsplit.RefNbr, newsplit.LineNbr, newsplit.ParentSplitLineNbr); if (parentschedule != null && parentschedule.Completed == true && parentschedule.POCompleted == true && parentschedule.BaseQty > parentschedule.BaseReceivedQty && deletedPlans.Exists(x => x.PlanID == parentschedule.PlanID)) { serviceOrder.Current = (FSServiceOrder)PXParentAttribute.SelectParent(soDetSplit.Cache, parentschedule, typeof(FSServiceOrder)); parentschedule = PXCache <FSSODetSplit> .CreateCopy(parentschedule); INItemPlan demand = PXCache <INItemPlan> .CreateCopy(deletedPlans.First(x => x.PlanID == parentschedule.PlanID)); UpdateSchedulesFromCompletedPO(graph, soDetSplit, initemplan, parentschedule, serviceOrder, demand); } prevSplit = newsplit; } //Added because of MySql AutoIncrement counters behavior foreach (FSSODetSplit split in splitsToDeletePlanID) { FSSODetSplit schedule = (FSSODetSplit)soDetSplit.Cache.Locate(split); if (schedule != null) { schedule.PlanID = null; soDetSplit.Cache.Update(schedule); } } return(returnList); }
//TODO:refactor public static void SOCreateProc(List <SOFixedDemand> list, DateTime?PurchDate) { SOOrderEntry docgraph = PXGraph.CreateInstance <SOOrderEntry>(); SOSetup sosetup = docgraph.sosetup.Current; DocumentList <SOOrder> created = new DocumentList <SOOrder>(docgraph); docgraph.ExceptionHandling.AddHandler <SOLineSplit.qty>((cache, e) => { e.Cancel = true; }); docgraph.ExceptionHandling.AddHandler <SOLineSplit.isAllocated>((cache, e) => { ((SOLineSplit)e.Row).IsAllocated = true; e.Cancel = true; }); foreach (SOFixedDemand demand in list) { string OrderType = sosetup.TransferOrderType ?? SOOrderTypeConstants.TransferOrder; string demandPlanType = demand.PlanType; try { if (demand.SourceSiteID == null) { PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.MissingSourceSite); continue; } SOOrder order; SOLineSplit2 sosplit = PXSelect <SOLineSplit2, Where <SOLineSplit2.planID, Equal <Required <SOLineSplit2.planID> > > > .Select(docgraph, demand.PlanID); if (sosplit != null) { order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, sosplit.ToSiteID, sosplit.SiteID); } else { if (demand.SourceSiteID == demand.SiteID) { PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.EqualSourceDestinationSite); continue; } order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, demand.SiteID, demand.SourceSiteID); } if (order == null) { order = new SOOrder(); } if (order.OrderNbr == null) { docgraph.Clear(); if (sosplit != null) { INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, sosplit.SiteID); order.BranchID = sourceSite.BranchID; order.OrderType = OrderType; order = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order)); order.DefaultSiteID = sosplit.SiteID; order.DestinationSiteID = sosplit.ToSiteID; order.OrderDate = PurchDate; docgraph.Document.Update(order); } else { INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, demand.SourceSiteID); order.BranchID = sourceSite.BranchID; order.OrderType = OrderType; order = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order)); order.DefaultSiteID = demand.SourceSiteID; order.DestinationSiteID = demand.SiteID; order.OrderDate = PurchDate; docgraph.Document.Update(order); } } else if (docgraph.Document.Cache.ObjectsEqual(docgraph.Document.Current, order) == false) { docgraph.Document.Current = docgraph.Document.Search <SOOrder.orderNbr>(order.OrderNbr, order.OrderType); } SOLine newline; SOLineSplit newsplit; PXCache cache = docgraph.Caches[typeof(INItemPlan)]; INItemPlan rp; if (sosplit != null) { docgraph.Transactions.Current = newline = docgraph.Transactions.Search <SOLine.inventoryID, SOLine.subItemID, SOLine.siteID, SOLine.pOCreate>(demand.InventoryID, demand.SubItemID, demand.SiteID, false); if (newline == null) { newline = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert()); newline.InventoryID = demand.InventoryID; newline.SubItemID = demand.SubItemID; newline.SiteID = demand.SiteID; newline.UOM = demand.UOM; newline.OrderQty = 0m; newline = docgraph.Transactions.Update(newline); } newsplit = new SOLineSplit(); newsplit.LotSerialNbr = sosplit.LotSerialNbr; newsplit.IsAllocated = true; newsplit.IsMergeable = false; newsplit.SiteID = demand.SiteID; //SiteID should be explicitly set because of PXFormula newsplit.Qty = demand.OrderQty; newsplit.RefNoteID = demand.RefNoteID; //we have to delete previous allocation and reinsert it after the newsplit for transfer-order allocation to work properly rp = PXCache <INItemPlan> .CreateCopy(demand); cache.RaiseRowDeleted(demand); newsplit = docgraph.splits.Insert(newsplit); sosplit.SOOrderType = newsplit.OrderType; sosplit.SOOrderNbr = newsplit.OrderNbr; sosplit.SOLineNbr = newsplit.LineNbr; sosplit.SOSplitLineNbr = newsplit.SplitLineNbr; docgraph.sodemand.Update(sosplit); rp.SiteID = sosplit.ToSiteID; rp.PlanType = INPlanConstants.Plan93; rp.FixedSource = null; rp.SupplyPlanID = newsplit.PlanID; cache.RaiseRowInserted(rp); cache.SetStatus(rp, PXEntryStatus.Updated); } else { docgraph.Transactions.Current = newline = docgraph.Transactions.Search <SOLine.inventoryID, SOLine.subItemID, SOLine.siteID, SOLine.pOCreate>(demand.InventoryID, demand.SubItemID, demand.SourceSiteID, demand.VendorID != null); if (newline == null) { newline = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert()); newline.InventoryID = demand.InventoryID; newline.SubItemID = demand.SubItemID; newline.SiteID = demand.SourceSiteID; newline.UOM = demand.UOM; newline.OrderQty = 0m; //newline.POCreate = (demand.VendorID != null); newline.POCreate = (demand.FixedSource == INReplenishmentSource.TransferToPurchase); newline.VendorID = demand.VendorID; //newline.VendorLocationID = demand.VendorLocationID; newline = docgraph.Transactions.Update(newline); } newsplit = new SOLineSplit(); newsplit.IsAllocated = false; newsplit.Qty = demand.OrderQty; //newsplit.POCreate = (demand.VendorID != null); newsplit.POCreate = (demand.FixedSource == INReplenishmentSource.TransferToPurchase); newsplit.VendorID = demand.VendorID; //newsplit.VendorLocationID = demand.VendorLocationID; newsplit = docgraph.splits.Insert(newsplit) ?? docgraph.splits.Current; rp = PXCache <INItemPlan> .CreateCopy(demand); cache.RaiseRowDeleted(demand); rp.SiteID = demand.SiteID; rp.PlanType = INPlanConstants.Plan94; rp.FixedSource = null; rp.SupplyPlanID = newsplit.PlanID; cache.RaiseRowInserted(rp); cache.SetStatus(rp, PXEntryStatus.Updated); } if (newsplit.PlanID == null) { throw new PXRowPersistedException(typeof(SOLine).Name, newline, RQ.Messages.UnableToCreateSOOrders); } if (docgraph.Transactions.Cache.IsInsertedUpdatedDeleted) { using (PXTransactionScope scope = new PXTransactionScope()) { docgraph.Save.Press(); if (demandPlanType == INPlanConstants.Plan90) { docgraph.Replenihment.Current = docgraph.Replenihment.Search <INReplenishmentOrder.noteID>(demand.RefNoteID); if (docgraph.Replenihment.Current != null) { INReplenishmentLine rLine = PXCache <INReplenishmentLine> .CreateCopy(docgraph.ReplenishmentLines.Insert(new INReplenishmentLine())); rLine.InventoryID = newsplit.InventoryID; rLine.SubItemID = newsplit.SubItemID; rLine.UOM = newsplit.UOM; rLine.Qty = newsplit.Qty; rLine.SOType = newsplit.OrderType; rLine.SONbr = docgraph.Document.Current.OrderNbr; rLine.SOLineNbr = newsplit.LineNbr; rLine.SOSplitLineNbr = newsplit.SplitLineNbr; rLine.SiteID = demand.SourceSiteID; rLine.DestinationSiteID = demand.SiteID; rLine.PlanID = demand.PlanID; docgraph.ReplenishmentLines.Update(rLine); INItemPlan plan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .SelectWindowed(docgraph, 0, 1, demand.SupplyPlanID); if (plan != null) { //plan.SupplyPlanID = rp.PlanID; rp.SupplyPlanID = plan.PlanID; cache.SetStatus(rp, PXEntryStatus.Updated); } docgraph.Save.Press(); } } scope.Complete(); } PXProcessing <SOFixedDemand> .SetInfo(list.IndexOf(demand), PXMessages.LocalizeFormatNoPrefixNLA(Messages.TransferOrderCreated, docgraph.Document.Current.OrderNbr)); if (created.Find(docgraph.Document.Current) == null) { created.Add(docgraph.Document.Current); } } } catch (Exception e) { PXProcessing <SOFixedDemand> .SetError(list.IndexOf(demand), e); } } if (created.Count == 1) { using (new PXTimeStampScope(null)) { docgraph.Clear(); docgraph.Document.Current = docgraph.Document.Search <POOrder.orderNbr>(created[0].OrderNbr, created[0].OrderType); throw new PXRedirectRequiredException(docgraph, Messages.SOOrder); } } }
public static void SOCreateProc(List <SOFixedDemand> list, DateTime?PurchDate) { SOOrderEntry docgraph = PXGraph.CreateInstance <SOOrderEntry>(); SOSetup sosetup = docgraph.sosetup.Current; DocumentList <SOOrder> created = new DocumentList <SOOrder>(docgraph); foreach (SOFixedDemand demand in list) { string OrderType = sosetup.TransferOrderType ?? SOOrderTypeConstants.TransferOrder; string ErrorText = string.Empty; try { if (demand.ReplenishmentSourceSiteID == null) { PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.MissingSourceSite); continue; } if (demand.ReplenishmentSourceSiteID == demand.SiteID) { PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.EqualSourceDestinationSite); continue; } SOOrder order; POLine poline = PXSelect <POLine, Where <POLine.planID, Equal <Required <POLine.planID> > > > .Select(docgraph, demand.PlanID); if (poline != null) { order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID, SOOrder.origPOType, SOOrder.origPONbr>( OrderType, demand.SiteID, demand.ReplenishmentSourceSiteID, poline.OrderType, poline.OrderNbr); } else { order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, demand.SiteID, demand.ReplenishmentSourceSiteID); } if (order == null) { order = new SOOrder(); } if (order.OrderNbr == null) { docgraph.Clear(); INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, demand.ReplenishmentSourceSiteID); order.BranchID = sourceSite.BranchID; order.OrderType = OrderType; order = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order)); order.DefaultSiteID = demand.ReplenishmentSourceSiteID; order.DestinationSiteID = demand.SiteID; order.Status = SOOrderStatus.Open; order.OrderDate = PurchDate; if (poline != null) { order.OrigPOType = poline.OrderType; order.OrigPONbr = poline.OrderNbr; } docgraph.Document.Update(order); } else if (docgraph.Document.Cache.ObjectsEqual(docgraph.Document.Current, order) == false) { docgraph.Document.Current = docgraph.Document.Search <SOOrder.orderNbr>(order.OrderNbr, order.OrderType); } SOLine line = new SOLine(); line = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert(line)); line.InventoryID = demand.InventoryID; line.SubItemID = demand.SubItemID; line.SiteID = demand.ReplenishmentSourceSiteID; line.UOM = demand.UOM; line.OrderQty = demand.OrderQty; if (poline != null) { line.OrigPOType = poline.OrderType; line.OrigPONbr = poline.OrderNbr; line.OrigPOLineNbr = poline.LineNbr; } line = docgraph.Transactions.Update(line); if (line.PlanID == null) { throw new PXRowPersistedException(typeof(SOLine).Name, line, RQ.Messages.UnableToCreateSOOrders); } PXCache cache = docgraph.Caches[typeof(INItemPlan)]; string demandPlanType = demand.PlanType; //cache.SetStatus(demand, PXEntryStatus.Updated); //demand.SupplyPlanID = line.PlanID; INItemPlan rp = PXCache <INItemPlan> .CreateCopy(demand); cache.RaiseRowDeleted(demand); rp.PlanType = INPlanConstants.Plan94; rp.FixedSource = null; rp.SupplyPlanID = line.PlanID; cache.RaiseRowInserted(rp); cache.SetStatus(rp, PXEntryStatus.Updated); if (docgraph.Transactions.Cache.IsInsertedUpdatedDeleted) { using (PXTransactionScope scope = new PXTransactionScope()) { docgraph.Save.Press(); if (demandPlanType == INPlanConstants.Plan90) { docgraph.Replenihment.Current = docgraph.Replenihment.Search <INReplenishmentOrder.noteID>(demand.RefNoteID); if (docgraph.Replenihment.Current != null) { INReplenishmentLine rLine = PXCache <INReplenishmentLine> .CreateCopy(docgraph.ReplenishmentLines.Insert(new INReplenishmentLine())); rLine.InventoryID = line.InventoryID; rLine.SubItemID = line.SubItemID; rLine.UOM = line.UOM; rLine.Qty = line.OrderQty; rLine.SOType = line.OrderType; rLine.SONbr = docgraph.Document.Current.OrderNbr; rLine.SOLineNbr = line.LineNbr; rLine.SiteID = demand.ReplenishmentSourceSiteID; rLine.DestinationSiteID = demand.SiteID; rLine.PlanID = demand.PlanID; docgraph.ReplenishmentLines.Update(rLine); INItemPlan plan = PXSelect <INItemPlan, Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .SelectWindowed(docgraph, 0, 1, demand.SupplyPlanID); if (plan != null) { //plan.SupplyPlanID = rp.PlanID; rp.SupplyPlanID = plan.PlanID; cache.SetStatus(rp, PXEntryStatus.Updated); } docgraph.Save.Press(); } } scope.Complete(); } PXProcessing <SOFixedDemand> .SetInfo(list.IndexOf(demand), string.Format(Messages.TransferOrderCreated, docgraph.Document.Current.OrderNbr) + "\r\n" + ErrorText); if (created.Find(docgraph.Document.Current) == null) { created.Add(docgraph.Document.Current); } } } catch (Exception e) { PXProcessing <SOFixedDemand> .SetError(list.IndexOf(demand), e); } } }
protected virtual void _(Events.RowPersisted <INItemPlan> e) { if (e.Row == null) { return; } if (e.TranStatus == PXTranStatus.Open) { INItemPlan inItemPlanRow = (INItemPlan)e.Row; if (e.Operation == PXDBOperation.Update) { if (inItemPlanRow.SupplyPlanID != null && inItemPlanRow.PlanType == INPlanConstants.PlanF6) { FSSODet fsSODetRow = FSSODetFixedDemand.Select(inItemPlanRow.PlanID); if (fsSODetRow != null) { POLine poLineRow = Base.Transactions.Select().Where(x => ((POLine)x).PlanID == inItemPlanRow.SupplyPlanID).First(); fsSODetRow.POType = Base.Document.Current.OrderType; fsSODetRow.PONbr = Base.Document.Current.OrderNbr; fsSODetRow.POLineNbr = poLineRow.LineNbr; fsSODetRow.POStatus = Base.Document.Current.Status; FSSODetFixedDemand.Update(fsSODetRow); FSSODetFixedDemand.Cache.Persist(PXDBOperation.Update); FSSODetSplit fsSODetSplitRow = FSSODetSplitFixedDemand.Select(inItemPlanRow.PlanID); if (fsSODetSplitRow != null) { fsSODetSplitRow.POType = Base.Document.Current.OrderType; fsSODetSplitRow.PONbr = Base.Document.Current.OrderNbr; fsSODetSplitRow.POLineNbr = poLineRow.LineNbr; FSSODetSplitFixedDemand.Update(fsSODetSplitRow); FSSODetSplitFixedDemand.Cache.Persist(PXDBOperation.Update); } } } } else if (e.Operation == PXDBOperation.Delete && (inItemPlanRow.PlanType == INPlanConstants.PlanF7 || inItemPlanRow.PlanType == INPlanConstants.PlanF8) ) { inItemPlanRow = PXSelect <INItemPlan, Where <INItemPlan.supplyPlanID, Equal <Required <INItemPlan.supplyPlanID> > > > .Select(Base, inItemPlanRow.PlanID); if (inItemPlanRow != null && inItemPlanRow.SupplyPlanID != null) { FSSODet fsSODetRow = FSSODetFixedDemand.Select(inItemPlanRow.PlanID); if (fsSODetRow != null) { fsSODetRow.POType = null; fsSODetRow.PONbr = null; fsSODetRow.POLineNbr = null; fsSODetRow.POStatus = null; FSSODetFixedDemand.Update(fsSODetRow); FSSODetFixedDemand.Cache.Persist(PXDBOperation.Update); inItemPlanRow.SupplyPlanID = null; Base.Caches[typeof(INItemPlan)].Update(inItemPlanRow); Base.Caches[typeof(INItemPlan)].Persist(PXDBOperation.Update); FSSODetSplit fsSODetSplitRow = FSSODetSplitFixedDemand.Select(inItemPlanRow.PlanID); if (fsSODetSplitRow != null) { fsSODetSplitRow.POType = null; fsSODetSplitRow.PONbr = null; fsSODetSplitRow.POLineNbr = null; FSSODetSplitFixedDemand.Update(fsSODetSplitRow); FSSODetSplitFixedDemand.Cache.Persist(PXDBOperation.Update); } } } } } }