public virtual int?GetDefaultLaborItem(PXGraph graph, EPEmployee employee, string earningType, int?projectID)
        {
            if (employee == null)
            {
                return(null);
            }

            int?result = null;

            if (ProjectDefaultAttribute.IsProject(graph, projectID))
            {
                result = EPContractRate.GetProjectLaborClassID(graph, projectID.Value, employee.BAccountID.Value, earningType);
            }

            if (result == null)
            {
                result = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, earningType);
            }

            if (result == null)
            {
                result = employee.LabourItemID;
            }

            return(result);
        }
Example #2
0
        public virtual int?GetDefaultLaborItem(int?employeeID, string earningType, int?projectID)
        {
            if (employeeID == null)
            {
                return(null);
            }

            int?result = null;

            if (ProjectDefaultAttribute.IsProject(this, projectID))
            {
                result = EPContractRate.GetProjectLaborClassID(this, projectID.Value, employeeID.Value, earningType);
            }

            if (result == null)
            {
                result = EPEmployeeClassLaborMatrix.GetLaborClassID(this, employeeID, earningType);
            }

            if (result == null)
            {
                EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Current <EPTimeCard.employeeID> > > > .Select(this);

                if (employee != null)
                {
                    result = employee.LabourItemID;
                }
            }

            return(result);
        }
Example #3
0
        public virtual void VerifyExchangeRateExistsForProject(int?newProjectID)
        {
            if (!PXAccess.FeatureInstalled <FeaturesSet.projectMultiCurrency>())
            {
                return;
            }

            if (!IsCommitmentsEnabled())
            {
                return;
            }

            PMProject project;

            if (ProjectDefaultAttribute.IsProject(Base, newProjectID, out project) && Base.Document.Current != null)
            {
                var curySettings = PMCommitmentAttribute.GetCurrencySettings(Base, newProjectID, Base.Document.Current.CuryID);

                if (!curySettings.UseBaseCurrency && curySettings.ConverionRequired)
                {
                    CM.Extensions.IPXCurrencyService currencyService = ServiceLocator.Current.GetInstance <Func <PXGraph, CM.Extensions.IPXCurrencyService> >()(Base);
                    var rate = currencyService.GetRate(curySettings.FromCuryID, curySettings.ToCuryID, curySettings.RateTypeID, Base.Document.Current.OrderDate.GetValueOrDefault(DateTime.Now));

                    if (rate == null)
                    {
                        var ex = new PXSetPropertyException(Messages.ConversionRateNotDefinedForCommitment, curySettings.FromCuryID, curySettings.ToCuryID, curySettings.RateTypeID, Base.Document.Current.OrderDate.GetValueOrDefault(DateTime.Now));
                        ex.ErrorValue = project.ContractCD;

                        throw ex;
                    }
                }
            }
        }
        public void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            EPEmployee employee = null;

            if (employeeSearch != null)
            {
                BqlCommand cmd  = BqlCommand.CreateInstance(employeeSearch);
                PXView     view = new PXView(sender.Graph, false, cmd);

                employee = view.SelectSingle() as EPEmployee;
            }

            if (employee != null && !string.IsNullOrEmpty(employee.UnionID))
            {
                HashSet <string> validUnions = new HashSet <string>();
                if (projectField != null)
                {
                    int?projectID = (int?)sender.GetValue(e.Row, projectField.Name);

                    if (ProjectDefaultAttribute.IsProject(sender.Graph, projectID))
                    {
                        var select = new PXSelect <PMProjectUnion, Where <PMProjectUnion.projectID, Equal <Required <PMProjectUnion.projectID> > > >(sender.Graph);
                        foreach (PMProjectUnion union in select.Select(projectID))
                        {
                            validUnions.Add(union.UnionID);
                        }
                    }
                }

                if (validUnions.Count == 0 || validUnions.Contains(employee.UnionID))
                {
                    e.NewValue = employee.UnionID;
                }
            }
        }
        private void SetViewPMTransEnabled(ARInvoice doc)
        {
            var       enabled = false;
            PMProject project;

            if (doc != null && ProjectDefaultAttribute.IsProject(Base, doc.ProjectID, out project))
            {
                enabled = project.BaseType == CT.CTPRType.Project;
            }

            Base.inquiry.SetEnabled(Messages.ViewPMTrans, enabled);
        }
        protected virtual void _(Events.FieldDefaulting <ARTran, ARTran.costCodeID> e)
        {
            PMProject project;

            if (CostCodeAttribute.UseCostCode() && ProjectDefaultAttribute.IsProject(Base, e.Row.ProjectID, out project))
            {
                if (project.BudgetLevel == BudgetLevels.Task)
                {
                    e.NewValue = CostCodeAttribute.GetDefaultCostCode();
                }
            }
        }
Example #7
0
        public virtual void VerifyProjectLockCommitments(int?newProjectID)
        {
            if (!PXAccess.FeatureInstalled <FeaturesSet.changeOrder>())
            {
                return;
            }

            PMProject project;

            if (ProjectDefaultAttribute.IsProject(Base, newProjectID, out project) && project.LockCommitments == true)
            {
                var ex = new PXSetPropertyException(PM.Messages.ProjectCommintmentsLocked);
                ex.ErrorValue = project.ContractCD;

                throw ex;
            }
        }
Example #8
0
 private PMProject GetProject(int?projectId)
 {
     ProjectDefaultAttribute.IsProject(Base, projectId, out var project);
     return(project);
 }
        private static void X_RowSelected <DAC>(
            PXCache cache,
            object eRow,
            EventType eventType,
            FSServiceOrder fsServiceOrderRow,
            FSSrvOrdType fsSrvOrdTypeRow,
            bool disableSODetReferenceFields,
            bool docAllowsActualFieldEdition)
            where DAC : class, IBqlTable, IFSSODetBase, new()
        {
            if (eRow == null)
            {
                return;
            }

            var row = (DAC)eRow;

            Type                 dacType              = typeof(DAC);
            FSSODet              fsSODetRow           = null;
            bool                 calledFromSO         = false;
            bool                 calledFromAPP        = false;
            FSAppointmentDet     fsAppointmentDetRow  = null;
            FSAppointmentDetPart fsAppointmentDetPart = null;

            if (dacType == typeof(FSAppointmentDet) ||
                dacType == typeof(FSAppointmentDetService) ||
                dacType == typeof(FSAppointmentDetPart) ||
                dacType == typeof(FSAppointmentInventoryItem))
            {
                fsAppointmentDetRow = (FSAppointmentDet)eRow;
                if (dacType == typeof(FSAppointmentDetPart))
                {
                    fsAppointmentDetPart = (FSAppointmentDetPart)eRow;
                }
                calledFromAPP = true;
            }
            else
            {
                fsSODetRow   = (FSSODet)eRow;
                calledFromSO = true;
            }


            bool isEnabled;
            PXPersistingCheck persistingCheck;
            bool isInventoryLine = IsInventoryLine(row.LineType);
            bool isStockItem;

            if (isInventoryLine == false)
            {
                isStockItem = false;
            }
            else
            {
                if (row.LineType != ID.LineType_All.SERVICE &&
                    row.LineType != ID.LineType_All.NONSTOCKITEM)
                {
                    isStockItem = true;
                }
                else
                {
                    isStockItem = false;
                }
            }


            // Enable/Disable SODetID
            SetEnabledAndPersistingCheck <FSSODet.sODetID>(cache, eRow, eventType,
                                                           isEnabled: !disableSODetReferenceFields, persistingCheck: null);


            // Enable/Disable LineType
            SetEnabledAndPersistingCheck <FSSODet.lineType>(cache, eRow, eventType,
                                                            isEnabled: !disableSODetReferenceFields, persistingCheck: null);


            // Set InventoryID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = true;
            persistingCheck = PXPersistingCheck.NullOrBlank;
            if (isInventoryLine == false)
            {
                isEnabled       = false;
                persistingCheck = PXPersistingCheck.Nothing;
            }
            else if (row.IsPrepaid == true ||
                     disableSODetReferenceFields == true ||
                     (calledFromSO == true && fsServiceOrderRow.AllowInvoice == true))
            {
                isEnabled = false;
            }

            SetEnabledAndPersistingCheck <FSSODet.inventoryID>(cache, eRow, eventType,
                                                               isEnabled, persistingCheck);


            if (PXAccess.FeatureInstalled <FeaturesSet.subItem>())
            {
                // Set SubItemID properties BASED ON InventoryID and LineType
                SetEnabledAndPersistingCheck <FSSODet.subItemID>(cache, eRow, eventType,
                                                                 isEnabled: isEnabled && isStockItem,
                                                                 persistingCheck: isStockItem == true ? persistingCheck : PXPersistingCheck.Nothing);
            }


            // Set UOM properties SAME AS InventoryID
            SetEnabledAndPersistingCheck <FSSODet.uOM>(cache, eRow, eventType,
                                                       isEnabled, persistingCheck);


            // Enable/Disable billingRule
            isEnabled = false;
            if ((row.LineType == ID.LineType_All.SERVICE || row.LineType == ID.LineType_All.NONSTOCKITEM) &&
                row.IsPrepaid == false &&
                (fsSODetRow == null || fsSODetRow.Mem_LastReferencedBy == null) &&
                (calledFromAPP == true || (calledFromSO == true && fsServiceOrderRow?.AllowInvoice == false)))
            {
                isEnabled = true;
            }

            SetEnabledAndPersistingCheck <FSSODet.billingRule>(cache, eRow, eventType,
                                                               isEnabled, persistingCheck: null);


            // Enable/Disable ManualPrice
            isEnabled = true;
            if (row.IsPrepaid == true ||
                isInventoryLine == false ||
                row.InventoryID == null ||
                (calledFromSO && fsServiceOrderRow?.AllowInvoice == true))
            {
                isEnabled = false;
            }

            SetEnabledAndPersistingCheck <FSSODet.manualPrice>(cache, eRow, eventType,
                                                               isEnabled, persistingCheck: null);


            // Enable/Disable IsBillable Same as ManualPrice

            SetEnabledAndPersistingCheck <FSSODet.isBillable>(cache, eRow, eventType,
                                                              isEnabled, persistingCheck: null);


            // Enable/Disable CuryUnitPrice
            isEnabled = false;
            if (row.BillingRule != ID.BillingRule.NONE &&
                row.IsPrepaid == false &&
                row.InventoryID != null &&
                (calledFromAPP == true || (calledFromSO == true && fsServiceOrderRow?.AllowInvoice == false)))
            {
                isEnabled = true;
            }

            SetEnabledAndPersistingCheck <FSSODet.curyUnitPrice>(cache, eRow, eventType,
                                                                 isEnabled, persistingCheck: null);



            // Enable/Disable EstimatedDuration and ActualDuration
            isEnabled = false;
            if (row.LineType == ID.LineType_All.SERVICE &&
                row.InventoryID != null &&
                (calledFromAPP == true || (calledFromSO == true && fsServiceOrderRow?.AllowInvoice == false)))
            {
                isEnabled = true;
            }

            SetEnabledAndPersistingCheck <FSSODet.estimatedDuration>(cache, eRow, eventType,
                                                                     isEnabled, persistingCheck: null);
            if (fsAppointmentDetRow != null)
            {
                //Enable when there is only 1 or 0 staff related to the service
                bool enableByStaffRelated = fsAppointmentDetRow.StaffRelatedCount < 2;
                SetEnabledAndPersistingCheck <FSAppointmentDet.actualDuration>(cache, eRow, eventType,
                                                                               isEnabled: isEnabled && docAllowsActualFieldEdition && enableByStaffRelated, persistingCheck: null);
            }


            // Enable/Disable EstimatedQty and ActualQty
            isEnabled = false;
            if (isInventoryLine == true &&
                row.BillingRule != ID.BillingRule.TIME &&
                row.IsPrepaid == false &&
                row.InventoryID != null &&
                (fsAppointmentDetPart == null || (string.IsNullOrEmpty(fsAppointmentDetPart.LotSerialNbr) == true ||
                                                  (string.IsNullOrEmpty(fsAppointmentDetPart.LotSerialNbr) == false &&
                                                   fsAppointmentDetPart.LotSerTrack != INLotSerTrack.SerialNumbered))) &&
                (calledFromAPP == true || (calledFromSO == true && fsServiceOrderRow?.AllowInvoice == false)))
            {
                isEnabled = true;
            }

            SetEnabledAndPersistingCheck <FSSODet.estimatedQty>(cache, eRow, eventType,
                                                                isEnabled, persistingCheck: null);
            if (fsAppointmentDetRow != null)
            {
                SetEnabledAndPersistingCheck <FSAppointmentDet.qty>(cache, eRow, eventType,
                                                                    isEnabled: isEnabled && docAllowsActualFieldEdition, persistingCheck: null);
            }


            // Set SiteID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = false;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == true && row.InventoryID != null)
            {
                if (row.IsPrepaid == false)
                {
                    if (fsAppointmentDetPart != null)
                    {
                        isEnabled = fsAppointmentDetPart.SODetID == null;
                    }
                    else
                    {
                        isEnabled = true;
                    }
                }

                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.siteID>(cache, eRow, eventType,
                                                          isEnabled, persistingCheck);


            // Set SiteLocationID properties SAME AS SiteID
            SetEnabledAndPersistingCheck <FSSODet.siteLocationID>(cache, eRow, eventType,
                                                                  isEnabled, persistingCheck);


            // Set ProjectID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = false;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == true && row.InventoryID != null)
            {
                isEnabled       = true;
                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.projectID>(cache, eRow, eventType,
                                                             isEnabled, persistingCheck);


            // Set ProjectTaskID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = true;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == false || row.InventoryID == null)
            {
                isEnabled = false;
            }
            else if (ProjectDefaultAttribute.IsProject(cache.Graph, row.ProjectID) == true)
            {
                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.projectTaskID>(cache, eRow, eventType,
                                                                 isEnabled, persistingCheck);


            // Set CostCodeID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = true;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == false || row.InventoryID == null)
            {
                isEnabled = false;
            }
            else if (ProjectDefaultAttribute.IsProject(cache.Graph, row.ProjectID) == true)
            {
                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.costCodeID>(cache, eRow, eventType,
                                                              isEnabled, persistingCheck);


            // Set AcctID properties (SetEnabled and SetPersistingCheck)
            isEnabled       = false;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == true &&
                row.InventoryID != null &&
                fsServiceOrderRow?.Quote == false &&
                fsSrvOrdTypeRow?.Behavior != ID.Behavior_SrvOrderType.INTERNAL_APPOINTMENT)
            {
                isEnabled       = true;
                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.acctID>(cache, eRow, eventType,
                                                          isEnabled, persistingCheck);


            // Set SubID properties SAME AS AcctID
            SetEnabledAndPersistingCheck <FSSODet.subID>(cache, eRow, eventType,
                                                         isEnabled, persistingCheck);


            // Set PickupDeliveryServiceID properties (SetEnabled and SetPersistingCheck)
            if (fsAppointmentDetRow != null && dacType == typeof(FSAppointmentInventoryItem))
            {
                isEnabled       = false;
                persistingCheck = PXPersistingCheck.Nothing;
                if (row.LineType == ID.LineType_All.PICKUP_DELIVERY)
                {
                    isEnabled       = true;
                    persistingCheck = PXPersistingCheck.NullOrBlank;
                }

                SetEnabledAndPersistingCheck <FSAppointmentInventoryItem.pickupDeliveryServiceID>(cache, eRow, eventType,
                                                                                                  isEnabled, persistingCheck);
            }


            // Set IsBillable properties (SetEnabled and SetPersistingCheck)

            isEnabled = true;
            if (row.ContractRelated == true || row.IsPrepaid == true)
            {
                isEnabled = false;
            }

            SetEnabledAndPersistingCheck <FSSODet.isBillable>(cache, eRow, eventType,
                                                              isEnabled, persistingCheck: null);

            // Set TranDesc properties (SetEnabled and SetPersistingCheck)
            isEnabled       = true;
            persistingCheck = PXPersistingCheck.Nothing;
            if (isInventoryLine == false)
            {
                persistingCheck = PXPersistingCheck.NullOrBlank;
            }

            SetEnabledAndPersistingCheck <FSSODet.tranDesc>(cache, eRow, eventType,
                                                            isEnabled, persistingCheck);

            isEnabled       = false;
            persistingCheck = PXPersistingCheck.Nothing;
            if (fsSODetRow != null && fsSODetRow.EnablePO == true)
            {
                persistingCheck = PXPersistingCheck.NullOrBlank;
                isEnabled       = true;
            }

            SetEnabledAndPersistingCheck <FSSODet.curyUnitCost>(cache, eRow, eventType,
                                                                isEnabled, persistingCheck);


            SharedFunctions.UpdateEquipmentAction(cache, eRow);
            // Additional Enable/Disable for Equipment fields
            if ((calledFromSO == true && fsServiceOrderRow?.AllowInvoice == true))
            {
                isEnabled = false;
                SetEnabledAndPersistingCheck <FSSODet.SMequipmentID>(cache, eRow, eventType,
                                                                     isEnabled, persistingCheck: null);
            }
        }