示例#1
0
        public virtual bool AllParametersEntered(PMLaborCostRate row)
        {
            if (row.Type == PMLaborCostRateType.Employee)
            {
                return(row.EmployeeID != null);
            }
            else if (row.Type == PMLaborCostRateType.Union)
            {
                return(row.UnionID != null && row.InventoryID != null);
            }
            else if (row.Type == PMLaborCostRateType.Certified)
            {
                return(row.ProjectID != null && row.InventoryID != null);
            }
            else if (row.Type == PMLaborCostRateType.Project)
            {
                return(row.ProjectID != null);
            }
            else if (row.Type == PMLaborCostRateType.Item)
            {
                return(row.InventoryID != null);
            }

            return(false);
        }
示例#2
0
        public virtual DateTime?GetMinEffectiveDate(PMLaborCostRate row)
        {
            if (row == null)
            {
                return(null);
            }

            if (!AllParametersEntered(row))
            {
                return(null);
            }

            DateTime?result = null;

            EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > .Select(this, row.EmployeeID);

            if (employee != null)
            {
                PMTimeActivity firstUnreleased = PXSelect <PMTimeActivity, Where <PMTimeActivity.ownerID, Equal <Required <PMTimeActivity.ownerID> >,
                                                                                  And <PMTimeActivity.released, NotEqual <True> > >,
                                                           OrderBy <Asc <PMTimeActivity.date> > > .SelectWindowed(this, 0, 1, employee.OwnerID);

                if (firstUnreleased != null)
                {
                    if (firstUnreleased.Date < result)
                    {
                        result = firstUnreleased.Date;
                    }
                }
            }

            return(result);
        }
示例#3
0
        public virtual DateTime?GetProjectOrEmployeeStartDate(PMLaborCostRate row)
        {
            if (row == null)
            {
                return(null);
            }

            if (!AllParametersEntered(row))
            {
                return(null);
            }

            DateTime?result = null;

            DateTime?employeeDate = null;
            DateTime?projectDate  = null;

            if (row.EmployeeID != null)
            {
                EPEmployeePosition activePosition = PXSelect <EPEmployeePosition, Where <EPEmployeePosition.employeeID, Equal <Required <EPEmployeePosition.employeeID> >,
                                                                                         And <EPEmployeePosition.isActive, Equal <True> > > > .Select(this, row.EmployeeID);

                if (activePosition != null)
                {
                    employeeDate = activePosition.StartDate;
                }
            }

            if (row.ProjectID != null)
            {
                PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID);

                if (project != null)
                {
                    projectDate = project.StartDate;
                }
            }

            if (employeeDate != null && projectDate != null)
            {
                if (employeeDate > projectDate)
                {
                    result = employeeDate;
                }
                else
                {
                    result = projectDate;
                }
            }
            else
            {
                result = employeeDate ?? projectDate;
            }

            return(result);
        }
示例#4
0
        protected virtual void _(Events.FieldVerifying <PMLaborCostRate, PMLaborCostRate.effectiveDate> e)
        {
            PMLaborCostRate latestDuplicate = GetLatestDuplicate(e.Row);
            DateTime?       newValue        = (DateTime?)e.NewValue;

            if (latestDuplicate != null && latestDuplicate.EffectiveDate != null)
            {
                if (newValue != null && newValue.Value.Date <= latestDuplicate.EffectiveDate.Value.Date)
                {
                    throw new PXSetPropertyException(Messages.EffectiveDateShouldBeGreater, latestDuplicate.EffectiveDate);
                }
            }
            else
            {
                DateTime?minEffectiveDate = GetMinEffectiveDate(e.Row);
                if (newValue != null && minEffectiveDate != null && newValue.Value.Date > minEffectiveDate.Value.Date)
                {
                    throw new PXSetPropertyException(Messages.EffectiveDateShouldBeLess, minEffectiveDate.Value.AddDays(1));
                }
            }
        }
示例#5
0
        protected virtual void _(Events.FieldDefaulting <PMLaborCostRate, PMLaborCostRate.effectiveDate> e)
        {
            if (e.Row != null)
            {
                PMLaborCostRate latestDuplicate = GetLatestDuplicate(e.Row);

                if (latestDuplicate != null && latestDuplicate.EffectiveDate != null)
                {
                    if (latestDuplicate.EffectiveDate.Value.Date < Accessinfo.BusinessDate)
                    {
                        e.NewValue = Accessinfo.BusinessDate;
                    }
                }
                else if (AllParametersEntered(e.Row))
                {
                    DateTime?minDate = GetMinEffectiveDate(e.Row);
                    if (minDate != null)
                    {
                        e.NewValue = minDate;
                    }
                    else
                    {
                        DateTime?startDate = GetProjectOrEmployeeStartDate(e.Row);
                        if (startDate != null)
                        {
                            e.NewValue = startDate;
                        }
                        else
                        {
                            e.NewValue = Accessinfo.BusinessDate;
                        }
                    }
                }
                else
                {
                    e.NewValue = Accessinfo.BusinessDate;
                }
            }
        }
示例#6
0
        protected virtual void _(Events.FieldDefaulting <PMLaborCostRate, PMLaborCostRate.inventoryID> e)
        {
            if (Filter.Current != null && Filter.Current.InventoryID != null)
            {
                e.NewValue = Filter.Current.InventoryID;
            }
            else if (e.Row.EmployeeID != null)
            {
                EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPEmployee.bAccountID> > > > .Select(this, e.Row.EmployeeID);

                if (employee != null)
                {
                    PMLaborCostRate existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.employeeID, Equal <Required <PMLaborCostRate.employeeID> >,
                                                                                 And <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                                                      And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                                           And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > > > .Select(this, e.Row.EmployeeID, employee.LabourItemID, e.Row.Type, e.Row.RecordID);

                    if (existing == null)
                    {
                        e.NewValue = employee.LabourItemID;
                    }
                }
            }
        }
示例#7
0
        public virtual PMLaborCostRate GetLatestDuplicate(PMLaborCostRate row)
        {
            if (row == null)
            {
                return(null);
            }

            PMLaborCostRate existing = null;

            if (row.Type == PMLaborCostRateType.Employee)
            {
                if (row.InventoryID != null)
                {
                    existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.employeeID, Equal <Required <PMLaborCostRate.employeeID> >,
                                                                 And <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                                      And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                           And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > >,
                                         OrderBy <Desc <PMLaborCostRate.effectiveDate> > > .SelectWindowed(this, 0, 1, row.EmployeeID, row.InventoryID, row.Type, row.RecordID);
                }
                else
                {
                    existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.employeeID, Equal <Required <PMLaborCostRate.employeeID> >,
                                                                 And <PMLaborCostRate.inventoryID, IsNull,
                                                                      And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                           And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > >,
                                         OrderBy <Desc <PMLaborCostRate.effectiveDate> > > .SelectWindowed(this, 0, 1, row.EmployeeID, row.Type, row.RecordID);
                }
            }
            else if (row.Type == PMLaborCostRateType.Union)
            {
                existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.unionID, Equal <Required <PMLaborCostRate.unionID> >,
                                                             And <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                                  And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                       And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > >,
                                     OrderBy <Desc <PMLaborCostRate.effectiveDate> > > .SelectWindowed(this, 0, 1, row.UnionID, row.InventoryID, row.Type, row.RecordID);
            }
            else if (row.Type == PMLaborCostRateType.Certified)
            {
                existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.projectID, Equal <Required <PMLaborCostRate.projectID> >,
                                                             And <PMLaborCostRate.taskID, IsNull,
                                                                  And <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                                       And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                            And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > > >,
                                     OrderBy <Desc <PMLaborCostRate.effectiveDate> > > .SelectWindowed(this, 0, 1, row.ProjectID, row.InventoryID, row.Type, row.RecordID);
            }
            else if (row.Type == PMLaborCostRateType.Project)
            {
                List <object> args = null;
                PXSelectBase <PMLaborCostRate> select = null;

                if (row.InventoryID != null)
                {
                    select = new PXSelect <PMLaborCostRate, Where <PMLaborCostRate.projectID, Equal <Required <PMLaborCostRate.projectID> >,
                                                                   And <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                                        And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                             And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > >,
                                           OrderBy <Desc <PMLaborCostRate.effectiveDate> > >(this);

                    args = new List <object>(new object[] { row.ProjectID, row.InventoryID, row.Type, row.RecordID });
                }
                else
                {
                    select = new PXSelect <PMLaborCostRate, Where <PMLaborCostRate.projectID, Equal <Required <PMLaborCostRate.projectID> >,
                                                                   And <PMLaborCostRate.inventoryID, IsNull,
                                                                        And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                             And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > > >,
                                           OrderBy <Desc <PMLaborCostRate.effectiveDate> > >(this);

                    args = new List <object>(new object[] { row.ProjectID, row.Type, row.RecordID });
                }

                if (row.TaskID != null)
                {
                    select.WhereAnd <Where <PMLaborCostRate.taskID, Equal <Required <PMLaborCostRate.taskID> > > >();
                    args.Add(row.TaskID);
                }
                else
                {
                    select.WhereAnd <Where <PMLaborCostRate.taskID, IsNull> >();
                }

                if (row.EmployeeID != null)
                {
                    select.WhereAnd <Where <PMLaborCostRate.employeeID, Equal <Required <PMLaborCostRate.employeeID> > > >();
                    args.Add(row.EmployeeID);
                }
                else
                {
                    select.WhereAnd <Where <PMLaborCostRate.employeeID, IsNull> >();
                }

                existing = select.SelectWindowed(0, 1, args.ToArray());
            }
            else if (row.Type == PMLaborCostRateType.Item)
            {
                existing = PXSelect <PMLaborCostRate, Where <PMLaborCostRate.inventoryID, Equal <Required <PMLaborCostRate.inventoryID> >,
                                                             And <PMLaborCostRate.type, Equal <Required <PMLaborCostRate.type> >,
                                                                  And <PMLaborCostRate.recordID, NotEqual <Required <PMLaborCostRate.recordID> > > > >,
                                     OrderBy <Desc <PMLaborCostRate.effectiveDate> > > .SelectWindowed(this, 0, 1, row.InventoryID, row.Type, row.RecordID);
            }

            return(existing);
        }