Beispiel #1
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);
        }
Beispiel #2
0
        ///NO CRM Mode
        public static int?GetContractLaborClassID(PXGraph graph, int?contractID, PMTimeActivity activity)
        {
            EPContractRate matrix =
                PXSelectJoin <
                    EPContractRate,
                    InnerJoin <EPEmployee,
                               On <EPContractRate.employeeID, Equal <EPEmployee.bAccountID> > >,
                    Where <EPContractRate.contractID, Equal <Required <EPContractRate.contractID> >,
                           And <EPContractRate.earningType, Equal <Required <CRPMTimeActivity.earningTypeID> >,
                                And <EPEmployee.userID, Equal <Required <CRPMTimeActivity.ownerID> > > > > > .Select(graph, contractID, activity.EarningTypeID, activity.OwnerID);

            if (matrix == null)
            {
                matrix =
                    PXSelect <
                        EPContractRate,
                        Where <EPContractRate.contractID, Equal <Required <EPContractRate.contractID> >,
                               And <EPContractRate.earningType, Equal <Required <CRPMTimeActivity.earningTypeID> >,
                                    And <EPContractRate.employeeID, IsNull> > > > .Select(graph, contractID, activity.EarningTypeID);
            }
            if (matrix != null)
            {
                return(matrix.LabourItemID);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public virtual int?GetLaborClass(PMTimeActivity activity, EPEmployee employee, CRCase refCase)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee", Messages.EmptyEmployeeID);
            }

            int?laborClassID = null;

            if (refCase != null)
            {
                CRCaseClass caseClass = (CRCaseClass)PXSelectorAttribute.Select <CRCase.caseClassID>(graph.Caches[typeof(CRCase)], refCase);
                if (caseClass.PerItemBilling == BillingTypeListAttribute.PerActivity)
                {
                    laborClassID = CRCaseClassLaborMatrix.GetLaborClassID(graph, caseClass.CaseClassID, activity.EarningTypeID);
                }
            }

            if (laborClassID == null && activity.ProjectID != null && employee.BAccountID != null)
            {
                laborClassID = EPContractRate.GetProjectLaborClassID(graph, (int)activity.ProjectID, (int)employee.BAccountID, activity.EarningTypeID);
            }

            if (laborClassID == null)
            {
                laborClassID = EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employee.BAccountID, activity.EarningTypeID);
            }

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

            return(laborClassID);
        }
        private void UpdateSODetServiceRow(
            ServiceOrderEntry graphServiceOrder,
            FSSODetService fsSODetServiceRow,
            PMTimeActivity pmTimeActivity,
            FSxPMTimeActivity fsxPMTimeActivity)
        {
            //TODO SD-7788
            //**************************************************************
            // Update all FSSODetService fields but key fields *************
            //**************************************************************
            if (fsSODetServiceRow.LineType != ID.LineType_ServiceTemplate.SERVICE)
            {
                graphServiceOrder.ServiceOrderDetServices.SetValueExt <FSSODetService.lineType>(fsSODetServiceRow, ID.LineType_ServiceTemplate.SERVICE);
            }

            if (fsSODetServiceRow.InventoryID != fsxPMTimeActivity.ServiceID)
            {
                graphServiceOrder.ServiceOrderDetServices.SetValueExt <FSSODetService.inventoryID>(fsSODetServiceRow, fsxPMTimeActivity.ServiceID);
            }

            if (fsSODetServiceRow.ProjectID != pmTimeActivity.ProjectID)
            {
                graphServiceOrder.ServiceOrderDetServices.SetValueExt <FSSODetService.projectID>(fsSODetServiceRow, pmTimeActivity.ProjectID);
            }

            if (fsSODetServiceRow.ProjectTaskID != pmTimeActivity.ProjectTaskID)
            {
                graphServiceOrder.ServiceOrderDetServices.SetValueExt <FSSODetService.projectTaskID>(fsSODetServiceRow, pmTimeActivity.ProjectTaskID);
            }

            if (fsSODetServiceRow.CostCodeID != pmTimeActivity.CostCodeID)
            {
                graphServiceOrder.ServiceOrderDetServices.SetValueExt <FSSODetService.costCodeID>(fsSODetServiceRow, pmTimeActivity.CostCodeID);
            }
        }
Beispiel #5
0
        protected virtual void PMTimeActivity_ProjectTaskID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMTimeActivity row = (PMTimeActivity)e.Row;

            if (row == null)
            {
                return;
            }

            if (e.NewValue != null && e.NewValue is int)
            {
                PMTask task = PXSelect <PMTask> .Search <PMTask.taskID>(sender.Graph, e.NewValue);

                if (task != null)
                {
                    if (task.IsCompleted == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectTaskIsCompleted);
                        ex.ErrorValue = task.TaskCD;
                        throw ex;
                    }
                    if (task.IsCancelled == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectTaskIsCanceled);
                        ex.ErrorValue = task.TaskCD;
                        throw ex;
                    }
                }
            }
        }
Beispiel #6
0
        public virtual decimal?CalculateEmployeeCost(PMTimeActivity activity, int?employeeID, DateTime date)
        {
            decimal?cost;
            Rate    employeeRate = GetEmployeeRate(activity.ProjectID, activity.ProjectTaskID, employeeID, date);

            if (employeeRate.Type == RateTypesAttribute.SalaryWithExemption && activity.TimeCardCD != null)
            {
                //Overtime is not applicable. Rate is prorated based on actual hours worked on the given week

                EPTimeCard timecard = PXSelect <EPTimeCard,
                                                Where <EPTimeCard.timeCardCD, Equal <Required <PMTimeActivity.timeCardCD> > > > .Select(graph, activity.TimeCardCD);

                if (timecard.TotalSpentCalc <= employeeRate.RegularHours * 60m)
                {
                    cost = employeeRate.RateByType / employeeRate.RegularHours;
                }
                else
                {
                    cost = employeeRate.RateByType / (timecard.TotalSpentCalc / 60m);
                }
            }
            else
            {
                cost = employeeRate.HourlyRate * GetOvertimeMultiplier(activity.EarningTypeID, (int)employeeID, date);
            }

            return(cost);
        }
Beispiel #7
0
        public virtual void UpdateServiceOrderDetail(PXCache cache, CRActivity crActivityRow, PXDBOperation operation)
        {
            FSServiceOrder fsServiceOrderRow = GetServiceOrderRecord(cache.Graph, crActivityRow);

            if (fsServiceOrderRow != null)
            {
                PMTimeActivity pmTimeActivityRow = PXSelect <PMTimeActivity,
                                                             Where <
                                                                 PMTimeActivity.refNoteID, Equal <Required <PMTimeActivity.refNoteID> > > >
                                                   .Select(Base, crActivityRow.NoteID);

                if (pmTimeActivityRow == null)
                {
                    return;
                }

                FSxPMTimeActivity fsxPMTimeActivityRow = PXCache <PMTimeActivity> .GetExtension <FSxPMTimeActivity>(pmTimeActivityRow);

                ServiceOrderEntry graphServiceOrder = PXGraph.CreateInstance <ServiceOrderEntry>();

                //Load existing ServiceOrder
                graphServiceOrder.ServiceOrderRecords.Current = graphServiceOrder.ServiceOrderRecords
                                                                .Search <FSServiceOrder.refNbr>(fsServiceOrderRow.RefNbr, fsServiceOrderRow.SrvOrdType);

                //Update ServiceOrder detail
                InsertUpdateDeleteSODet(graphServiceOrder, pmTimeActivityRow, fsxPMTimeActivityRow, operation);

                if (graphServiceOrder.IsDirty)
                {
                    graphServiceOrder.Save.Press();
                }
            }
        }
        protected void EPEarningType_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            EPEarningType row = (EPEarningType)e.Row;

            if (row == null)
            {
                return;
            }

            EPSetup setup = PXSelect <
                EPSetup
                , Where <EPSetup.regularHoursType, Equal <Required <EPEarningType.typeCD> >
                         , Or <EPSetup.holidaysType, Equal <Required <EPEarningType.typeCD> >
                               , Or <EPSetup.vacationsType, Equal <Required <EPEarningType.typeCD> > >
                               >
                         >
                > .Select(this, row.TypeCD, row.TypeCD, row.TypeCD);

            if (setup != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            CRCaseClassLaborMatrix caseClassLabor = PXSelect <CRCaseClassLaborMatrix, Where <CRCaseClassLaborMatrix.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (caseClassLabor != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            EPContractRate contractRate = PXSelect <EPContractRate, Where <EPContractRate.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (contractRate != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            EPEmployeeClassLaborMatrix employeeLabor = PXSelect <EPEmployeeClassLaborMatrix, Where <EPEmployeeClassLaborMatrix.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (employeeLabor != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            PMTimeActivity activity = PXSelect <PMTimeActivity, Where <PMTimeActivity.earningTypeID, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (activity != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }

            PMTran pmTran = PXSelect <PMTran, Where <PMTran.earningType, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.TypeCD);

            if (pmTran != null)
            {
                throw new PXException(Messages.CannotDeleteInUse);
            }
        }
        public static void UpdateReportedInTimeZoneIDIfNeeded(PXCache cache, PMTimeActivity row, DateTime?oldValue, DateTime?newValue)
        {
            if (oldValue != newValue)
            {
                string timeZoneID = newValue != null?LocaleInfo.GetTimeZone()?.Id : null;

                cache.SetValueExt <PMTimeActivity.reportedInTimeZoneID>(row, timeZoneID);
            }
        }
Beispiel #10
0
        protected virtual void _(Events.FieldUpdated <CRActivity, CRActivity.uistatus> e)
        {
            PMTimeActivity timeActivity = (PMTimeActivity)TimeActivity.SelectSingle();

            if (timeActivity != null)
            {
                Caches[typeof(PMTimeActivity)].MarkUpdated(timeActivity);                //For Persisting event handler to sync Status.
            }
        }
Beispiel #11
0
        public static void PMTimeActivity_RowSelected_Handler(PXCache cache, PMTimeActivity pmTimeActivityRow)
        {
            FSxPMTimeActivity fsxPMTimeActivityRow = cache.GetExtension <FSxPMTimeActivity>(pmTimeActivityRow);

            PXUIFieldAttribute.SetEnabled <FSxPMTimeActivity.appointmentID>(cache, pmTimeActivityRow, false);
            PXUIFieldAttribute.SetEnabled <FSxPMTimeActivity.appointmentCustomerID>(cache, pmTimeActivityRow, false);
            PXUIFieldAttribute.SetEnabled <FSxPMTimeActivity.sOID>(cache, pmTimeActivityRow, false);
            PXUIFieldAttribute.SetEnabled <FSxPMTimeActivity.appEmpID>(cache, pmTimeActivityRow, false);
            PXUIFieldAttribute.SetEnabled <FSxPMTimeActivity.serviceID>(cache, pmTimeActivityRow, false);
        }
Beispiel #12
0
        public virtual int?GetLaborClass(PMTimeActivity activity)
        {
            CRCase refCase = PXSelectJoin <CRCase,
                                           InnerJoin <CRActivityLink,
                                                      On <CRActivityLink.refNoteID, Equal <CRCase.noteID> > >,
                                           Where <CRActivityLink.noteID, Equal <Required <PMTimeActivity.refNoteID> > > > .Select(graph, activity.RefNoteID);

            EPEmployee employee = PXSelect <EPEmployee> .Search <EPEmployee.userID>(graph, activity.OwnerID);

            return(GetLaborClass(activity, employee, refCase));
        }
Beispiel #13
0
        public static string GetCalendarID(PXGraph graph, PMTimeActivity act)
        {
            var projectCalendar = act.ProjectID.
                                  With(_ => (CT.Contract)PXSelect <CT.Contract,
                                                                   Where <CT.Contract.contractID, Equal <Required <CT.Contract.contractID> > > > .
                                       Select(graph, _.Value)).
                                  With(_ => _.CalendarID);

            if (projectCalendar != null)
            {
                return(projectCalendar);
            }

            var projectTaskCalendar = act.ProjectTaskID.
                                      With(_ => (PXResult <Location, PM.PMTask>)PXSelectJoin <Location,
                                                                                              InnerJoin <PM.PMTask, On <PM.PMTask.customerID, Equal <Location.bAccountID>, And <PM.PMTask.locationID, Equal <Location.locationID> > > >,
                                                                                              Where <PM.PMTask.taskID, Equal <Required <PM.PMTask.taskID> > > > .
                                           Select(graph, _.Value)).
                                      With(_ => ((Location)_).CCalendarID);

            if (projectTaskCalendar != null)
            {
                return(projectTaskCalendar);
            }

            var caseLocationCalendar = act.RefNoteID.
                                       With(_ => (PXResult <Location, CRCase>)PXSelectJoin <Location,
                                                                                            InnerJoin <CRCase,
                                                                                                       On <CRCase.customerID, Equal <Location.bAccountID>,
                                                                                                           And <CRCase.locationID, Equal <Location.locationID> > >,
                                                                                                       InnerJoin <CRActivityLink,
                                                                                                                  On <CRActivityLink.refNoteID, Equal <CRCase.noteID> > > >,
                                                                                            Where <CRActivityLink.noteID, Equal <Required <PMTimeActivity.refNoteID> > > > .
                                            Select(graph, _.Value)).
                                       With(_ => ((Location)_).CCalendarID);

            if (caseLocationCalendar != null)
            {
                return(caseLocationCalendar);
            }

            var employeeCalendar = act.OwnerID.
                                   With(_ => (EPEmployee)PXSelect <EPEmployee,
                                                                   Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .
                                        Select(graph, _.Value)).
                                   With(_ => _.CalendarID);

            if (employeeCalendar != null)
            {
                return(employeeCalendar);
            }

            return(null);
        }
Beispiel #14
0
        public virtual LaborCost CalculateEmployeeCost(string timeCardCD, string earningTypeID, int?laborItemID, int?projectID, int?projectTaskID, bool?certifiedJob, string unionID, int?employeeID, DateTime date)
        {
            decimal?cost;
            decimal overtimeMult = 1;
            Rate    employeeRate = GetEmployeeRate(laborItemID, projectID, projectTaskID, certifiedJob, unionID, employeeID, date);

            if (employeeRate == null)
            {
                return(null);
            }

            if (employeeRate.Type == RateTypesAttribute.SalaryWithExemption && timeCardCD != null)
            {
                //Overtime is not applicable. Rate is prorated based on actual hours worked on the given week

                EPTimeCard timecard = PXSelect <EPTimeCard,
                                                Where <EPTimeCard.timeCardCD, Equal <Required <PMTimeActivity.timeCardCD> > > > .Select(graph, timeCardCD);

                if (timecard.TotalSpentCalc == null)
                {
                    var            select = new PXSelectGroupBy <PMTimeActivity, Where <PMTimeActivity.timeCardCD, Equal <Required <PMTimeActivity.timeCardCD> > >, Aggregate <Sum <PMTimeActivity.timeSpent> > >(graph);
                    PMTimeActivity total  = select.Select(timeCardCD);

                    timecard.TotalSpentCalc = total.TimeSpent;
                }

                if (timecard.TotalSpentCalc <= employeeRate.RegularHours * 60m)
                {
                    cost = employeeRate.RateByType / employeeRate.RegularHours;
                }
                else
                {
                    cost = employeeRate.RateByType / (timecard.TotalSpentCalc / 60m);
                }
            }
            else
            {
                overtimeMult = GetOvertimeMultiplier(earningTypeID, employeeRate);
                cost         = employeeRate.HourlyRate * overtimeMult;
            }

            return(new LaborCost(cost, overtimeMult));
        }
        private void UpdateSubject(PXCache cache, PMTimeActivity pmTimeActivityRow, CRActivity crActivityRow)
        {
            FSxPMTimeActivity fsxPMTimeActivityRow = cache.GetExtension <FSxPMTimeActivity>(pmTimeActivityRow);

            //Clean the Subject
            if (crActivityRow.Subject != null)
            {
                int positionPipe = crActivityRow.Subject.IndexOf("|");

                if (positionPipe != -1)
                {
                    crActivityRow.Subject = crActivityRow.Subject.Substring(positionPipe + 1).Trim();

                    if (crActivityRow.Subject == string.Empty)
                    {
                        crActivityRow.Subject = null;
                    }
                }
            }

            if (fsxPMTimeActivityRow.ServiceID != null)
            {
                InventoryItem inventoryItemRow = PXSelect <InventoryItem,
                                                           Where <
                                                               InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > >
                                                 .Select(Base, fsxPMTimeActivityRow.ServiceID);

                if (inventoryItemRow != null)
                {
                    if (inventoryItemRow.ItemType == INItemTypes.ServiceItem)
                    {
                        if (string.IsNullOrWhiteSpace(crActivityRow.Subject))
                        {
                            crActivityRow.Subject = string.Empty;
                        }

                        crActivityRow.Subject = TX.ModuleName.SERVICE_DESCRIPTOR + inventoryItemRow.Descr + " | " + crActivityRow.Subject;
                    }
                }
            }
        }
        public static int?GetContractLaborClassID(PXGraph graph, PMTimeActivity activity)
        {
            EPContractRate matrix =
                PXSelectJoin <
                    EPContractRate,
                    InnerJoin <CRCase,
                               On <CRCase.contractID, Equal <EPContractRate.contractID> >,
                               InnerJoin <CRActivityLink,
                                          On <CRActivityLink.refNoteID, Equal <CRCase.noteID> >,
                                          InnerJoin <EPEmployee,
                                                     On <EPContractRate.employeeID, Equal <EPEmployee.bAccountID> > > > >,
                    Where <CRActivityLink.noteID, Equal <Required <PMTimeActivity.refNoteID> >,
                           And <EPContractRate.earningType, Equal <Required <PMTimeActivity.earningTypeID> >,
                                And <EPEmployee.userID, Equal <Required <PMTimeActivity.ownerID> > > > > >
                .Select(graph, new object[] { activity.RefNoteID, activity.EarningTypeID, activity.OwnerID });

            if (matrix == null)
            {
                matrix =
                    PXSelectJoin <
                        EPContractRate,
                        InnerJoin <CRCase,
                                   On <CRCase.contractID, Equal <EPContractRate.contractID> >,
                                   InnerJoin <CRActivityLink,
                                              On <CRActivityLink.refNoteID, Equal <CRCase.noteID> > > >,
                        Where <CRActivityLink.noteID, Equal <Required <PMTimeActivity.refNoteID> >,
                               And <EPContractRate.earningType, Equal <Required <PMTimeActivity.earningTypeID> >,
                                    And <EPContractRate.employeeID, IsNull> > > >
                    .Select(graph, new object[] { activity.RefNoteID, activity.EarningTypeID });
            }

            if (matrix != null)
            {
                return(matrix.LabourItemID);
            }
            else
            {
                return(null);
            }
        }
        private void InsertUpdateDeleteSODet(
            ServiceOrderEntry graphServiceOrder,
            PMTimeActivity pmTimeActivityRow,
            FSxPMTimeActivity fsxPMTimeActivityRow,
            PXDBOperation operation)
        {
            FSSODetService fsSODetServiceRow;

            graphServiceOrder.ServiceOrderDetServices.Current = graphServiceOrder.ServiceOrderDetServices
                                                                .Search <FSSODet.sourceNoteID>(pmTimeActivityRow.NoteID);
            if (graphServiceOrder.ServiceOrderDetServices.Current != null)
            {
                if (operation == PXDBOperation.Delete || fsxPMTimeActivityRow.ServiceID == null)
                {
                    graphServiceOrder.ServiceOrderDetServices.Delete(graphServiceOrder.ServiceOrderDetServices.Current);
                    return;
                }
            }
            else
            {
                //This line does not require appointment
                if (fsxPMTimeActivityRow.ServiceID == null)
                {
                    return;
                }

                //Insert a new SODet line
                fsSODetServiceRow = new FSSODetService();

                //Assign the PMTimeActivity reference to the new FSSODet line
                fsSODetServiceRow.SourceNoteID = pmTimeActivityRow.NoteID;

                graphServiceOrder.ServiceOrderDetServices.Current = graphServiceOrder.ServiceOrderDetServices.Insert(fsSODetServiceRow);
            }

            //Update the SODet line
            UpdateSODetServiceRow(graphServiceOrder, graphServiceOrder.ServiceOrderDetServices.Current, pmTimeActivityRow, fsxPMTimeActivityRow);
        }
Beispiel #18
0
        protected virtual void PMTask_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            PMTask row = e.Row as PMTask;

            if (row == null)
            {
                return;
            }

            if (row.IsActive == true && row.IsCancelled == false)
            {
                throw new PXException(Messages.OnlyPlannedCanbeDeleted);
            }

            //validate that all child records can be deleted:

            PMTran tran = PXSelect <PMTran, Where <PMTran.projectID, Equal <Required <PMTask.projectID> >, And <PMTran.taskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (tran != null)
            {
                throw new PXException(Messages.HasTranData);
            }

            PMTimeActivity activity = PXSelect <PMTimeActivity, Where <PMTimeActivity.projectID, Equal <Required <PMTask.projectID> >, And <PMTimeActivity.projectTaskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (activity != null)
            {
                throw new PXException(Messages.HasActivityData);
            }

            EP.EPTimeCardItem timeCardItem = PXSelect <EP.EPTimeCardItem, Where <EP.EPTimeCardItem.projectID, Equal <Required <PMTask.projectID> >, And <EP.EPTimeCardItem.taskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (timeCardItem != null)
            {
                throw new PXException(Messages.HasTimeCardItemData);
            }
        }
Beispiel #19
0
        protected virtual void PMTimeActivity_ProjectID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMTimeActivity row = (PMTimeActivity)e.Row;

            if (row == null)
            {
                return;
            }

            if (e.NewValue != null && e.NewValue is int)
            {
                PMProject proj = PXSelect <PMProject> .Search <PMProject.contractID>(sender.Graph, e.NewValue);

                if (proj != null)
                {
                    if (proj.IsCompleted == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsCompleted);
                        ex.ErrorValue = proj.ContractCD;
                        throw ex;
                    }
                    if (proj.IsCancelled == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsCanceled);
                        ex.ErrorValue = proj.ContractCD;;
                        throw ex;
                    }
                    if (proj.Status == CT.Contract.status.Expired)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsSuspended);
                        ex.ErrorValue = proj.ContractCD;;
                        throw ex;
                    }
                }
            }
        }
Beispiel #20
0
        public static DateTime?GetNextActivityStartDate <Activity>(PXGraph graph, PXResultset <Activity> res, PMTimeActivity row, int?fromWeekId, int?tillWeekId, PXCache tempDataCache, Type tempDataField)
            where Activity : PMTimeActivity, new()
        {
            DateTime?date;

            if (fromWeekId != null || tillWeekId != null)
            {
                date = PXWeekSelector2Attribute.GetWeekStartDate(graph, (int)(fromWeekId ?? tillWeekId));
            }
            else
            {
                date = graph.Accessinfo.BusinessDate.GetValueOrDefault(DateTime.Now).Date;
            }

            EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, row.OwnerID);

            EPEmployeeClass employeeClass = PXSelect <EPEmployeeClass, Where <EPEmployeeClass.vendorClassID, Equal <Required <EPEmployee.vendorClassID> > > > .Select(graph, employee != null?employee.VendorClassID : null);

            var calendarId = CRActivityMaint.GetCalendarID(graph, row);

            if (employeeClass != null && EPEmployeeClass.defaultDateInActivity.LastDay == employeeClass.DefaultDateInActivity)
            {
                DateTime?val = tempDataCache.GetValue(tempDataCache.Current, tempDataField.Name) as DateTime?;
                if (val != null)
                {
                    int week = PXWeekSelector2Attribute.GetWeekID(graph, (DateTime)val);
                    if ((fromWeekId == null || week >= fromWeekId) && (tillWeekId == null || tillWeekId >= week))
                    {
                        date = val;
                    }
                }
            }
            else
            {
                DateTime weekDate = (DateTime)date;
                DateTime?newDate  = null;
                date = res != null && res.Count > 0 ? res.Max(_ => ((Activity)_).Date) : null ?? date;
                for (int curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate); tillWeekId == null || curentWeek <= tillWeekId; curentWeek = PXWeekSelector2Attribute.GetWeekID(graph, weekDate))
                {
                    PXWeekSelector2Attribute.WeekInfo week1 = PXWeekSelector2Attribute.GetWeekInfo(graph,
                                                                                                   PXWeekSelector2Attribute.GetWeekID(graph, weekDate));
                    foreach (KeyValuePair <DayOfWeek, PXWeekSelector2Attribute.DayInfo> pair in week1.Days.OrderBy(_ => _.Value.Date))
                    {
                        if (pair.Value.Date >= date &&
                            (CalendarHelper.IsWorkDay(graph, calendarId, (DateTime)pair.Value.Date) ||
                             string.IsNullOrEmpty(calendarId) && pair.Key != DayOfWeek.Saturday && pair.Key != DayOfWeek.Sunday))
                        {
                            newDate = (DateTime)pair.Value.Date;
                            break;
                        }
                        weekDate = weekDate.AddDays(1D);
                    }
                    if (newDate != null)
                    {
                        date = ((DateTime)newDate).Date;
                        break;
                    }
                }
            }

            if (!string.IsNullOrEmpty(calendarId) && date != null)
            {
                DateTime startDate;
                DateTime endDate;
                CalendarHelper.CalculateStartEndTime(graph, calendarId, (DateTime)date, out startDate, out endDate);
                date = startDate;
            }

            return(date);
        }
Beispiel #21
0
        public static TimeSpan CalculateOvertime(PXGraph graph, PMTimeActivity act, DateTime start, DateTime end)
        {
            var calendarId = GetCalendarID(graph, act);

            return(calendarId == null ? new TimeSpan() : CalendarHelper.CalculateOvertime(graph, start, end, calendarId));
        }
        public static void PMTimeActivity_RowPersisting_Handler(PXCache cache, PXGraph graph, PMTimeActivity pmTimeActivityRow, PXRowPersistingEventArgs e)
        {
            FSxPMTimeActivity fsxPMTimeActivityRow = PXCache <PMTimeActivity> .GetExtension <FSxPMTimeActivity>(pmTimeActivityRow);

            if (e.Operation == PXDBOperation.Delete &&
                graph.Accessinfo.ScreenID != SharedFunctions.SetScreenIDToDotFormat(ID.ScreenID.APPOINTMENT))
            {
                if (fsxPMTimeActivityRow.AppointmentID != null &&
                    fsxPMTimeActivityRow.LogLineNbr != null)
                {
                    PXUpdate <
                        Set <FSAppointmentLog.trackTime, False>,
                        FSAppointmentLog,
                        Where <
                            FSAppointmentLog.docID, Equal <Required <FSAppointmentLog.docID> >,
                            And <FSAppointmentLog.lineNbr, Equal <Required <FSAppointmentLog.lineNbr> > > > >
                    .Update(graph, fsxPMTimeActivityRow.AppointmentID, fsxPMTimeActivityRow.LogLineNbr);
                }
            }

            if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update) &&
                !IsAccessedFromAppointment(graph.Accessinfo.ScreenID))
            {
                if (fsxPMTimeActivityRow.AppointmentID != null &&
                    fsxPMTimeActivityRow.LogLineNbr != null &&
                    (
                        (int?)cache.GetValueOriginal <EPActivityApprove.timeSpent>(pmTimeActivityRow) != pmTimeActivityRow.TimeSpent ||
                        (int?)cache.GetValueOriginal <EPActivityApprove.timeBillable>(pmTimeActivityRow) != pmTimeActivityRow.TimeBillable ||
                        (bool?)cache.GetValueOriginal <EPActivityApprove.isBillable>(pmTimeActivityRow) != pmTimeActivityRow.IsBillable))
                {
                    AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();

                    FSAppointment fsAppointmentRow = PXSelect <FSAppointment,
                                                               Where <
                                                                   FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > >
                                                     .Select(graph, fsxPMTimeActivityRow.AppointmentID);

                    FSAppointmentLog fsAppointmentLogRow = PXSelect <FSAppointmentLog,
                                                                     Where <
                                                                         FSAppointmentLog.docID, Equal <Required <FSAppointmentLog.docID> >,
                                                                         And <FSAppointmentLog.lineNbr, Equal <Required <FSAppointmentLog.lineNbr> > > > >
                                                           .Select(graph, fsxPMTimeActivityRow.AppointmentID, fsxPMTimeActivityRow.LogLineNbr);

                    fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.appointmentID>
                                                                                              (fsAppointmentRow.AppointmentID, fsAppointmentRow.SrvOrdType);

                    graphAppointmentEntry.SkipTimeCardUpdate = true;
                    fsAppointmentLogRow.TimeDuration         = pmTimeActivityRow.TimeSpent;
                    fsAppointmentLogRow.EarningType          = pmTimeActivityRow.EarningTypeID;

                    FSSrvOrdType fsSrvOrdTypeRow = graphAppointmentEntry.ServiceOrderTypeSelected.Current;

                    if (fsSrvOrdTypeRow != null &&
                        fsSrvOrdTypeRow.PostTo == ID.SrvOrdType_PostTo.PROJECTS &&
                        fsSrvOrdTypeRow.BillingType == ID.SrvOrdType_BillingType.COST_AS_COST &&
                        fsSrvOrdTypeRow.CreateTimeActivitiesFromAppointment == true)
                    {
                        fsAppointmentLogRow.IsBillable           = pmTimeActivityRow.IsBillable;
                        fsAppointmentLogRow.BillableTimeDuration = pmTimeActivityRow.TimeBillable;
                    }

                    fsAppointmentLogRow = graphAppointmentEntry.LogRecords.Update(fsAppointmentLogRow);
                    graphAppointmentEntry.Save.Press();
                }
            }
        }
Beispiel #23
0
        ///NO CRM Mode
        public static PMTran CreateContractUsage(RegisterEntry graph, int?contractID, PMTimeActivity timeActivity, int billableMinutes)
        {
            if (timeActivity.ApprovalStatus == ActivityStatusListAttribute.Canceled)
            {
                return(null);
            }

            if (timeActivity.IsBillable != true)
            {
                return(null);
            }

            Contract contract = PXSelect <Contract,
                                          Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(graph, contractID);

            if (contract == null)
            {
                return(null);               //activity has no contract and will be billed through Project using the cost-transaction. Contract-Usage is not created in this case.
            }
            int?laborItemID = GetContractLaborClassID(graph, contractID, timeActivity);;

            if (laborItemID == null)
            {
                EPEmployee employeeSettings = PXSelect <EPEmployee,
                                                        Where <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > .Select(graph, timeActivity.OwnerID);

                if (employeeSettings != null)
                {
                    laborItemID =
                        EPEmployeeClassLaborMatrix.GetLaborClassID(graph, employeeSettings.BAccountID, timeActivity.EarningTypeID) ??
                        employeeSettings.LabourItemID;
                }
            }

            InventoryItem laborItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(graph, laborItemID);

            if (laborItem == null)
            {
                throw new PXException(PX.Objects.CR.Messages.LaborNotConfigured);
            }

            //save the sign of the value and do the rounding against absolute value.
            //reuse sign later when setting value to resulting transaction.
            int sign = billableMinutes < 0 ? -1 : 1;

            billableMinutes = Math.Abs(billableMinutes);


            if (billableMinutes > 0)
            {
                PMTran newLabourTran = new PMTran();
                newLabourTran.ProjectID      = contractID;
                newLabourTran.InventoryID    = laborItem.InventoryID;
                newLabourTran.AccountGroupID = contract.ContractAccountGroup;
                newLabourTran.OrigRefID      = timeActivity.NoteID;
                newLabourTran.BAccountID     = contract.CustomerID;
                newLabourTran.LocationID     = contract.LocationID;
                newLabourTran.Description    = timeActivity.Summary;
                newLabourTran.StartDate      = timeActivity.Date;
                newLabourTran.EndDate        = timeActivity.Date;
                newLabourTran.Date           = timeActivity.Date;
                newLabourTran.UOM            = laborItem.SalesUnit;
                newLabourTran.Qty            = sign * Convert.ToDecimal(TimeSpan.FromMinutes(billableMinutes).TotalHours);
                newLabourTran.BillableQty    = newLabourTran.Qty;
                newLabourTran.Released       = true;
                newLabourTran.Allocated      = true;
                newLabourTran.IsQtyOnly      = true;
                newLabourTran.BillingID      = contract.BillingID;
                return(graph.Transactions.Insert(newLabourTran));
            }
            else
            {
                return(null);
            }
        }
Beispiel #24
0
        public static void PMTimeActivity_RowPersisting_Handler(PXCache cache, PXGraph graph, PMTimeActivity pmTimeActivityRow, PXRowPersistingEventArgs e)
        {
            FSxPMTimeActivity fsxPMTimeActivityRow = PXCache <PMTimeActivity> .GetExtension <FSxPMTimeActivity>(pmTimeActivityRow);

            if (e.Operation == PXDBOperation.Delete &&
                graph.Accessinfo.ScreenID != SharedFunctions.SetScreenIDToDotFormat(ID.ScreenID.APPOINTMENT))
            {
                if (fsxPMTimeActivityRow.AppointmentID != null &&
                    fsxPMTimeActivityRow.AppEmpID != null)
                {
                    PXUpdate <Set <FSAppointmentEmployee.trackTime, False>,
                              FSAppointmentEmployee,
                              Where <
                                  FSAppointmentEmployee.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> >,
                                  And <FSAppointmentEmployee.lineNbr, Equal <Required <FSAppointmentEmployee.lineNbr> > > > >
                    .Update(graph, fsxPMTimeActivityRow.AppointmentID, fsxPMTimeActivityRow.AppEmpID);
                }
            }

            if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update) &&
                graph.Accessinfo.ScreenID != SharedFunctions.SetScreenIDToDotFormat(ID.ScreenID.APPOINTMENT))
            {
                if (fsxPMTimeActivityRow.AppointmentID != null &&
                    fsxPMTimeActivityRow.AppEmpID != null &&
                    fsxPMTimeActivityRow.ServiceID != null &&
                    (int?)cache.GetValueOriginal <EPActivityApprove.timeSpent>(pmTimeActivityRow) != pmTimeActivityRow.TimeSpent)
                {
                    AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();

                    FSAppointment fsAppointmentRow = PXSelect <FSAppointment,
                                                               Where <FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > >
                                                     .Select(graph, fsxPMTimeActivityRow.AppointmentID);

                    FSAppointmentEmployee fsAppointmentEmployeeRow = PXSelect <FSAppointmentEmployee,
                                                                               Where <
                                                                                   FSAppointmentEmployee.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> >,
                                                                                   And <FSAppointmentEmployee.lineNbr, Equal <Required <FSAppointmentEmployee.lineNbr> > > > >
                                                                     .Select(graph, fsxPMTimeActivityRow.AppointmentID, fsxPMTimeActivityRow.AppEmpID);

                    fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.appointmentID>
                                                                                              (fsAppointmentRow.AppointmentID, fsAppointmentRow.SrvOrdType);

                    graphAppointmentEntry.SkipTimeCardUpdate = true;
                    fsAppointmentEmployeeRow.ActualDuration  = pmTimeActivityRow.TimeSpent;
                    AppointmentDateTimeHelper.UpdateStaffActualDateTimeEndFromActualDuration(fsAppointmentEmployeeRow);
                    fsAppointmentEmployeeRow.EarningType = pmTimeActivityRow.EarningTypeID;
                    fsAppointmentEmployeeRow             = graphAppointmentEntry.AppointmentEmployees.Update(fsAppointmentEmployeeRow);
                    graphAppointmentEntry.Save.Press();
                }
            }
        }