Exemplo n.º 1
0
        public static void ClearScheduleReferences(ref FSSODetSplit schedule)
        {
            schedule.ParentSplitLineNbr = schedule.SplitLineNbr;
            schedule.SplitLineNbr       = null;
            schedule.Completed          = false;
            schedule.PlanID             = null;
            //clear PO references
            schedule.POCompleted = false;
            schedule.POCancelled = false;

            schedule.POCreate = false;
            schedule.POSource = INReplenishmentSource.None;

            schedule.POType        = null;
            schedule.PONbr         = null;
            schedule.POLineNbr     = null;
            schedule.POReceiptType = null;
            schedule.POReceiptNbr  = null;
            //clear SO references
            schedule.SOOrderType    = null;
            schedule.SOOrderNbr     = null;
            schedule.SOLineNbr      = null;
            schedule.SOSplitLineNbr = null;
            schedule.RefNoteID      = null;
        }
Exemplo n.º 2
0
        public virtual void FillPOLineFromDemand(POLine dest, POFixedDemand demand, string OrderType, SOLineSplit3 solinesplit, FillPOLineFromDemandDelegate del)
        {
            if (demand.PlanType == INPlanConstants.PlanF6)
            {
                PXResult <FSSODetSplit, FSSODet> fsSODetSplitDetRow =
                    (PXResult <FSSODetSplit, FSSODet>)
                    PXSelectJoin <FSSODetSplit,
                                  InnerJoin <FSSODet,
                                             On <
                                                 FSSODet.lineNbr, Equal <FSSODetSplit.lineNbr>,
                                                 And <FSSODet.srvOrdType, Equal <FSSODetSplit.srvOrdType>,
                                                      And <FSSODet.refNbr, Equal <FSSODetSplit.refNbr> > > > >,
                                  Where <
                                      FSSODetSplit.planID, Equal <Required <FSSODetSplit.planID> > > >
                    .Select(Base, demand.PlanID);

                if (fsSODetSplitDetRow != null)
                {
                    FSSODetSplit fsSODetSplitRow = (FSSODetSplit)fsSODetSplitDetRow;
                    FSSODet      fsSODetRow      = (FSSODet)fsSODetSplitDetRow;

                    dest.LineType = (fsSODetSplitRow.LineType == SO.SOLineType.Inventory
                                            ? POLineType.GoodsForServiceOrder
                                            : POLineType.NonStockForServiceOrder);

                    if (fsSODetRow.ManualCost == true)
                    {
                        dest.CuryUnitCost = fsSODetRow.CuryUnitCost;
                    }
                }
            }

            del(dest, demand, OrderType, solinesplit);
        }
 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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow)
        {
            if (docLinesGrouped.Count == 0)
            {
                return;
            }

            bool?initialHold = false;

            FSServiceOrder fsServiceOrderRow = docLines[0].fsServiceOrder;
            FSSrvOrdType   fsSrvOrdTypeRow   = docLines[0].fsSrvOrdType;
            FSPostDoc      fsPostDocRow      = docLines[0].fsPostDoc;
            FSAppointment  fsAppointmentRow  = docLines[0].fsAppointment;

            Base.FieldDefaulting.AddHandler <ARInvoice.branchID>((sender, e) =>
            {
                e.NewValue = fsServiceOrderRow.BranchID;
                e.Cancel   = true;
            });

            ARInvoice arInvoiceRow = new ARInvoice();

            if (invtMult >= 0)
            {
                arInvoiceRow.DocType = ARInvoiceType.Invoice;
                AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID);
            }
            else
            {
                arInvoiceRow.DocType = ARInvoiceType.CreditMemo;
                AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().CreditAdjNumberingID);
            }

            arInvoiceRow.DocDate     = invoiceDate;
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow.InvoiceNbr  = fsServiceOrderRow.CustPORefNbr;
            arInvoiceRow             = Base.Document.Insert(arInvoiceRow);
            initialHold         = arInvoiceRow.Hold;
            arInvoiceRow.NoteID = null;
            PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, arInvoiceRow);

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, true);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceOrderRow.BillCustomerID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceOrderRow.BillLocationID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyID>(arInvoiceRow, fsServiceOrderRow.CuryID);

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxZoneID>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID);
            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxCalcMode>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxCalcMode : fsServiceOrderRow.TaxCalcMode);

            string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceOrderRow.BillCustomerID, null);

            if (termsID != null)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID);
            }
            else
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSrvOrdTypeRow.DfltTermIDARSO);
            }

            if (fsServiceOrderRow.ProjectID != null)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceOrderRow.ProjectID);
            }

            Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, fsServiceOrderRow.DocDesc);
            arInvoiceRow.FinPeriodID = invoiceFinPeriodID;
            arInvoiceRow             = Base.Document.Update(arInvoiceRow);

            InvoicingFunctions.SetContactAndAddress(Base, fsServiceOrderRow);

            if (onDocumentHeaderInserted != null)
            {
                onDocumentHeaderInserted(Base, arInvoiceRow);
            }

            IDocLine  docLine      = null;
            ARTran    arTranRow    = null;
            FSxARTran fsxARTranRow = null;
            PMTask    pmTaskRow    = null;
            List <SharedClasses.SOARLineEquipmentComponent> componentList = new List <SharedClasses.SOARLineEquipmentComponent>();
            int?acctID;
            int?pivotAppointmentDetID = -1;

            foreach (DocLineExt docLineExt in docLines)
            {
                docLine = docLineExt.docLine;
                if (docLineExt.fsAppointment != null)
                {
                    if (pivotAppointmentDetID != docLineExt.docLine.LineID)
                    {
                        pivotAppointmentDetID = docLineExt.docLine.LineID;
                    }
                    else
                    {
                        continue;
                    }
                }

                FSSODetSplit fsSODetSplitRow = docLineExt.fsSODetSplit;
                fsPostDocRow      = docLineExt.fsPostDoc;
                fsServiceOrderRow = docLineExt.fsServiceOrder;
                fsSrvOrdTypeRow   = docLineExt.fsSrvOrdType;
                fsAppointmentRow  = docLineExt.fsAppointment;

                arTranRow = new ARTran();
                arTranRow = Base.Transactions.Insert(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.branchID>(arTranRow, docLine.BranchID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID);

                pmTaskRow = docLineExt.pmTask;

                if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed)
                {
                    throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD);
                }

                if (docLine.ProjectID != null && docLine.ProjectTaskID != null)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.UOM : docLine.UOM);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.siteID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.SiteID : docLine.SiteID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.locationID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.LocationID : docLine.SiteLocationID);

                if (docLine.IsService == true || fsAppointmentRow != null)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.GetQty(FieldType.BillableField));
                }
                else
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.Qty : docLine.GetQty(FieldType.BillableField));
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDesc);

                fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, fsAppointmentRow == null ? fsServiceOrderRow.SalesPersonID : fsAppointmentRow.SalesPersonID);

                if (docLine.AcctID != null)
                {
                    acctID = docLine.AcctID;
                }
                else
                {
                    acctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(graphProcess,
                                                                          fsSrvOrdTypeRow.SalesAcctSource,
                                                                          docLine.InventoryID,
                                                                          docLine.SiteID,
                                                                          fsServiceOrderRow);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID);

                if (docLine.SubID != null)
                {
                    try
                    {
                        Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID);
                    }
                    catch (PXException)
                    {
                        arTranRow.SubID = null;
                    }
                }
                else
                {
                    InvoicingFunctions.SetCombinedSubID(graphProcess,
                                                        Base.Transactions.Cache,
                                                        arTranRow,
                                                        null,
                                                        null,
                                                        fsSrvOrdTypeRow,
                                                        arTranRow.BranchID,
                                                        arTranRow.InventoryID,
                                                        arInvoiceRow.CustomerLocationID,
                                                        fsServiceOrderRow.BranchLocationID,
                                                        fsServiceOrderRow.SalesPersonID,
                                                        docLine.IsService);
                }

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualPrice>(arTranRow, docLine.ManualPrice);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice * invtMult);

                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taxCategoryID>(arTranRow, docLine.TaxCategoryID);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, fsAppointmentRow?.Commissionable ?? fsServiceOrderRow.Commissionable ?? false);
                Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID);

                if (docLine.IsBillable == false)
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualDisc>(arTranRow, true);
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyDiscAmt>(arTranRow, docLine.GetQty(FieldType.BillableField) * docLine.CuryUnitPrice * invtMult);
                }
                else
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, ((docLine.CuryBillableExtPrice * invtMult) / docLine.GetQty(FieldType.BillableField)) * arTranRow.Qty);
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct);
                }


                if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr);
                }
                else if (fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr);
                }

                fsxARTranRow                  = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow);
                fsxARTranRow.Source           = docLine.BillingBy;
                fsxARTranRow.SOID             = fsServiceOrderRow.SOID;
                fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate;

                fsxARTranRow.BillCustomerID     = fsServiceOrderRow.CustomerID;
                fsxARTranRow.CustomerLocationID = fsServiceOrderRow.LocationID;

                fsxARTranRow.SODetID         = docLine.PostSODetID;
                fsxARTranRow.AppointmentID   = docLine.PostAppointmentID;
                fsxARTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate;
                fsxARTranRow.AppDetID        = docLine.PostAppDetID;

                fsxARTranRow.Mem_PreviousPostID = docLine.PostID;
                fsxARTranRow.Mem_TableSource    = docLine.SourceTable;

                SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, arTranRow, docLine, fsSrvOrdTypeRow);
                fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow);

                if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr);
                }
                else if (fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr))
                {
                    Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr);
                }

                if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>())
                {
                    if (docLine.EquipmentAction != null)
                    {
                        Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentAction>(arTranRow, docLine.EquipmentAction);
                        Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.sMEquipmentID>(arTranRow, docLine.SMEquipmentID);
                        Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentLineRef>(arTranRow, docLine.EquipmentLineRef);

                        fsxARTranRow.Comment = docLine.Comment;

                        if (docLine.EquipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT ||
                            ((docLine.EquipmentAction == ID.Equipment_Action.CREATING_COMPONENT ||
                              docLine.EquipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT ||
                              docLine.EquipmentAction == ID.Equipment_Action.NONE) &&
                             string.IsNullOrEmpty(docLine.NewTargetEquipmentLineNbr) == false))
                        {
                            componentList.Add(new SharedClasses.SOARLineEquipmentComponent(docLine, arTranRow, fsxARTranRow));
                        }
                        else
                        {
                            fsxARTranRow.ComponentID = docLine.ComponentID;
                        }
                    }
                }

                if (onTransactionInserted != null)
                {
                    onTransactionInserted(Base, arTranRow);
                }
            }

            if (componentList.Count > 0)
            {
                //Assigning the NewTargetEquipmentLineNbr field value for the component type records
                foreach (SharedClasses.SOARLineEquipmentComponent currLineModel in componentList.Where(x => x.equipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT))
                {
                    foreach (SharedClasses.SOARLineEquipmentComponent currLineComponent in componentList.Where(x => (x.equipmentAction == ID.Equipment_Action.CREATING_COMPONENT ||
                                                                                                                     x.equipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT ||
                                                                                                                     x.equipmentAction == ID.Equipment_Action.NONE)))
                    {
                        if (currLineComponent.sourceNewTargetEquipmentLineNbr == currLineModel.sourceLineRef)
                        {
                            currLineComponent.fsxARTranRow.ComponentID = currLineComponent.componentID;
                            currLineComponent.fsxARTranRow.NewTargetEquipmentLineNbr = currLineModel.currentLineRef;
                        }
                    }
                }
            }

            arInvoiceRow = Base.Document.Update(arInvoiceRow);

            if (Base.ARSetup.Current.RequireControlTotal == true)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal);
            }

            if (initialHold != true || quickProcessFlow != PXQuickProcess.ActionFlow.NoFlow)
            {
                Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false);
            }

            arInvoiceRow = Base.Document.Update(arInvoiceRow);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
                            }
                        }
                    }
                }
            }
        }