public virtual void UpgradeEquipmentComponents(SMEquipmentMaint graphSMEquipmentMaint,
                                                       ARRegister arRegisterRow,
                                                       Dictionary <int?, int?> newEquiments)
        {
            var inventoryItemSet = PXSelectJoin <InventoryItem,
                                                 InnerJoin <ARTran,
                                                            On <ARTran.inventoryID, Equal <InventoryItem.inventoryID>,
                                                                And <ARTran.tranType, Equal <ARDocType.invoice> > >,
                                                            LeftJoin <SOLine,
                                                                      On <SOLine.orderType, Equal <ARTran.sOOrderType>,
                                                                          And <SOLine.orderNbr, Equal <ARTran.sOOrderNbr>,
                                                                               And <SOLine.lineNbr, Equal <ARTran.sOOrderLineNbr> > > > > >,
                                                 Where <
                                                     ARTran.tranType, Equal <Required <ARInvoice.docType> >,
                                                     And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                                          And <FSxARTran.equipmentAction, Equal <ListField_EquipmentAction.UpgradingComponent>,
                                                               And <FSxARTran.sMEquipmentID, IsNull,
                                                                    And <FSxARTran.newTargetEquipmentLineNbr, IsNotNull,
                                                                         And <FSxARTran.componentID, IsNotNull,
                                                                              And <FSxARTran.equipmentLineRef, IsNull> > > > > > >,
                                                 OrderBy <
                                                     Asc <ARTran.tranType,
                                                          Asc <ARTran.refNbr,
                                                               Asc <ARTran.lineNbr> > > > >
                                   .Select(Base, arRegisterRow.DocType, arRegisterRow.RefNbr);

            foreach (PXResult <InventoryItem, ARTran, SOLine> bqlResult in inventoryItemSet)
            {
                ARTran        arTranRow        = (ARTran)bqlResult;
                SOLine        soLineRow        = (SOLine)bqlResult;
                InventoryItem inventoryItemRow = (InventoryItem)bqlResult;
                FSxARTran     fsxARTranRow     = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow);

                int?smEquipmentID = -1;
                if (newEquiments.TryGetValue(fsxARTranRow.NewTargetEquipmentLineNbr, out smEquipmentID))
                {
                    graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(smEquipmentID);

                    FSEquipmentComponent fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Select().Where(x => ((FSEquipmentComponent)x).ComponentID == fsxARTranRow.ComponentID).FirstOrDefault();

                    if (fsEquipmentComponentRow != null)
                    {
                        fsEquipmentComponentRow.SalesOrderNbr    = arTranRow.SOOrderNbr;
                        fsEquipmentComponentRow.SalesOrderType   = arTranRow.SOOrderType;
                        fsEquipmentComponentRow.LongDescr        = arTranRow.TranDesc;
                        fsEquipmentComponentRow.InvoiceRefNbr    = arTranRow.RefNbr;
                        fsEquipmentComponentRow.InstallationDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate;

                        if (fsxARTranRow != null)
                        {
                            if (fsxARTranRow.AppointmentID != null)
                            {
                                fsEquipmentComponentRow.InstAppointmentID = fsxARTranRow.AppointmentID;
                                fsEquipmentComponentRow.InstallationDate  = fsxARTranRow.AppointmentDate;
                            }
                            else if (fsxARTranRow.SOID != null)
                            {
                                fsEquipmentComponentRow.InstServiceOrderID = fsxARTranRow.SOID;
                                fsEquipmentComponentRow.InstallationDate   = fsxARTranRow.ServiceOrderDate;
                            }

                            fsEquipmentComponentRow.Comment = fsxARTranRow.Comment;
                        }

                        fsEquipmentComponentRow.SerialNumber = arTranRow.LotSerialNbr;

                        fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Update(fsEquipmentComponentRow);

                        graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.inventoryID>(fsEquipmentComponentRow, arTranRow.InventoryID);
                        graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.salesDate>(fsEquipmentComponentRow, soLineRow != null && soLineRow.OrderDate != null ? soLineRow.OrderDate : arTranRow.TranDate);
                        graphSMEquipmentMaint.Save.Press();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ReplaceComponents(
            SMEquipmentMaint graphSMEquipmentMaint,
            ARRegister arRegisterRow)
        {
            var inventoryItemSet = PXSelectJoin <InventoryItem,
                                                 InnerJoin <ARTran,
                                                            On <ARTran.inventoryID, Equal <InventoryItem.inventoryID>,
                                                                And <ARTran.tranType, Equal <ARDocType.invoice> > >,
                                                            InnerJoin <SOLineSplit,
                                                                       On <SOLineSplit.orderType, Equal <ARTran.sOOrderType>,
                                                                           And <SOLineSplit.orderNbr, Equal <ARTran.sOOrderNbr>,
                                                                                And <SOLineSplit.lineNbr, Equal <ARTran.sOOrderLineNbr>,
                                                                                     And <SOLineSplit.qty, Greater <Zero> > > > >,
                                                                       InnerJoin <SOLine,
                                                                                  On <SOLine.orderType, Equal <SOLineSplit.orderType>,
                                                                                      And <SOLine.orderNbr, Equal <SOLineSplit.orderNbr>,
                                                                                           And <SOLine.lineNbr, Equal <SOLineSplit.lineNbr> > > >,
                                                                                  LeftJoin <SOShipLineSplit,
                                                                                            On <SOShipLineSplit.origOrderType, Equal <SOLineSplit.orderType>,
                                                                                                And <SOShipLineSplit.origOrderNbr, Equal <SOLineSplit.orderNbr>,
                                                                                                     And <SOShipLineSplit.origLineNbr, Equal <SOLineSplit.lineNbr>,
                                                                                                          And <SOShipLineSplit.origSplitLineNbr, Equal <SOLineSplit.splitLineNbr> > > > > > > > >,
                                                 Where <
                                                     ARTran.tranType, Equal <Required <ARInvoice.docType> >,
                                                     And <ARTran.refNbr, Equal <Required <ARInvoice.refNbr> >,
                                                          And <FSxEquipmentModel.eQEnabled, Equal <True>,
                                                               And <FSxSOLine.equipmentAction, Equal <ListField_EquipmentAction.ReplacingComponent>,
                                                                    And <FSxSOLine.sMEquipmentID, IsNotNull,
                                                                         And <FSxSOLine.newTargetEquipmentLineNbr, IsNull,
                                                                              And <FSxSOLine.equipmentLineRef, IsNotNull,
                                                                                   And <SOLineSplit.pOCreate, Equal <False> > > > > > > > >,
                                                 OrderBy <
                                                     Asc <ARTran.tranType,
                                                          Asc <ARTran.refNbr,
                                                               Asc <ARTran.lineNbr> > > > >
                                   .Select(Base, arRegisterRow.DocType, arRegisterRow.RefNbr);

            foreach (PXResult <InventoryItem, ARTran, SOLineSplit, SOLine, SOShipLineSplit> bqlResult in inventoryItemSet)
            {
                ARTran          arTranRow          = (ARTran)bqlResult;
                InventoryItem   inventoryItemRow   = (InventoryItem)bqlResult;
                SOLine          soLineRow          = (SOLine)bqlResult;
                SOLineSplit     soLineSplitRow     = (SOLineSplit)bqlResult;
                SOShipLineSplit soShipLineSplitRow = (SOShipLineSplit)bqlResult;
                FSxSOLine       fsxSOLineRow       = PXCache <SOLine> .GetExtension <FSxSOLine>(soLineRow);

                FSxARTran fsxARTranRow = PXCache <ARTran> .GetExtension <FSxARTran>(arTranRow);

                graphSMEquipmentMaint.EquipmentRecords.Current = graphSMEquipmentMaint.EquipmentRecords.Search <FSEquipment.SMequipmentID>(fsxSOLineRow.SMEquipmentID);

                FSEquipmentComponent fsEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Select().Where(x => ((FSEquipmentComponent)x).LineNbr == fsxSOLineRow.EquipmentLineRef).FirstOrDefault();

                FSEquipmentComponent fsNewEquipmentComponentRow = new FSEquipmentComponent();
                fsNewEquipmentComponentRow.ComponentID = fsxSOLineRow.ComponentID;
                fsNewEquipmentComponentRow             = graphSMEquipmentMaint.ApplyComponentReplacement(fsEquipmentComponentRow, fsNewEquipmentComponentRow);

                fsNewEquipmentComponentRow.SalesOrderNbr    = soLineRow.OrderNbr;
                fsNewEquipmentComponentRow.SalesOrderType   = soLineRow.OrderType;
                fsNewEquipmentComponentRow.InvoiceRefNbr    = arTranRow.RefNbr;
                fsNewEquipmentComponentRow.InstallationDate = arTranRow.TranDate != null ? arTranRow.TranDate : arRegisterRow.DocDate;

                if (fsxSOLineRow != null)
                {
                    if (fsxSOLineRow.AppointmentID != null)
                    {
                        fsNewEquipmentComponentRow.InstAppointmentID = fsxSOLineRow.AppointmentID;
                        fsNewEquipmentComponentRow.InstallationDate  = fsxSOLineRow.AppointmentDate;
                    }
                    else if (fsxSOLineRow.SOID != null)
                    {
                        fsNewEquipmentComponentRow.InstServiceOrderID = fsxSOLineRow.SOID;
                        fsNewEquipmentComponentRow.InstallationDate   = fsxSOLineRow.ServiceOrderDate;
                    }

                    fsNewEquipmentComponentRow.Comment = fsxSOLineRow.Comment;
                }

                fsNewEquipmentComponentRow.LongDescr = soLineRow.TranDesc;

                if (soLineSplitRow != null)
                {
                    fsNewEquipmentComponentRow.SerialNumber = soLineSplitRow.LotSerialNbr;
                }

                if (fsNewEquipmentComponentRow.SerialNumber == null &&
                    soShipLineSplitRow != null)
                {
                    fsNewEquipmentComponentRow.SerialNumber = soShipLineSplitRow.LotSerialNbr;
                }

                fsNewEquipmentComponentRow = graphSMEquipmentMaint.EquipmentWarranties.Update(fsNewEquipmentComponentRow);

                graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.inventoryID>(fsNewEquipmentComponentRow, soLineRow.InventoryID);
                graphSMEquipmentMaint.EquipmentWarranties.SetValueExt <FSEquipmentComponent.salesDate>(fsNewEquipmentComponentRow, soLineRow.OrderDate);
                graphSMEquipmentMaint.Save.Press();
            }
        }