Beispiel #1
0
 private static object GetProjectTaskIDToUseInEPActivityApprove(
     FSAppointment fsAppointmentRow,
     FSAppointmentEmployee fsAppointmentEmployeeRow,
     FSAppointmentDetService fsAppointmentDetServiceRow)
 {
     if (fsAppointmentEmployeeRow != null && fsAppointmentEmployeeRow.ServiceLineRef != null && fsAppointmentDetServiceRow != null)
     {
         return(fsAppointmentDetServiceRow.ProjectTaskID);
     }
     else
     {
         return(fsAppointmentRow.DfltProjectTaskID);
     }
 }
Beispiel #2
0
 private static string GetDescriptionToUseInEPActivityApprove(
     FSAppointment fsAppointmentRow,
     FSAppointmentEmployee fsAppointmentEmployeeRow,
     FSAppointmentDetService fsAppointmentDetServiceRow)
 {
     if (fsAppointmentEmployeeRow != null &&
         fsAppointmentEmployeeRow.ServiceLineRef != null &&
         fsAppointmentDetServiceRow != null)
     {
         return(fsAppointmentDetServiceRow.TranDesc);
     }
     else
     {
         return(fsAppointmentRow.DocDesc);
     }
 }
        private void CloneServices(AppointmentEntry sourceAppointmentGraph, AppointmentEntry newAppointmentGraph, FSAppointment newAppointmentRow)
        {
            foreach (FSAppointmentDetService sourceRow in sourceAppointmentGraph.AppointmentDetServices.Select())
            {
                FSSODet fsSODetRow = ServiceOrderCore.GetSODetFromAppointmentDet(sourceAppointmentGraph, sourceRow);

                if (fsSODetRow != null &&
                    (fsSODetRow.Status == ID.Status_AppointmentDet.CANCELED ||
                     fsSODetRow.Status == ID.Status_AppointmentDet.COMPLETED))
                {
                    continue;
                }

                FSAppointmentDetService newRow = PXCache <FSAppointmentDetService> .CreateCopy(sourceRow);

                newRow.ActualDuration      = 0;
                newRow.ActualDateTimeBegin = null;
                newRow.ActualDateTimeEnd   = null;
                newRow.Qty = 0;

                newRow = AppointmentEntry.InsertServicePartLine <FSAppointmentDetService, FSAppointmentDetService>(
                    newAppointmentGraph.AppointmentDetServices.Cache,
                    newRow,
                    sourceAppointmentGraph.AppointmentDetServices.Cache,
                    sourceRow,
                    null,
                    sourceRow.SODetID,
                    copyTranDate: false,
                    tranDate: sourceRow.TranDate,
                    SetValuesAfterAssigningSODetID: true,
                    copyingFromQuote: false);

                PXNoteAttribute.CopyNoteAndFiles(
                    sourceAppointmentGraph.AppointmentDetServices.Cache,
                    sourceRow,
                    newAppointmentGraph.AppointmentDetServices.Cache,
                    newRow,
                    copyNotes: true,
                    copyFiles: false);


                newAppointmentGraph.AppointmentDetServices.SetValueExt <FSAppointmentDetService.acctID>(newRow, sourceRow.AcctID);
                newAppointmentGraph.AppointmentDetServices.SetValueExt <FSAppointmentDetService.subID>(newRow, sourceRow.SubID);

                AppointmentCore.UpdateAppointmentsInfoInServiceOrder(newAppointmentGraph.AppointmentDetServices.Cache, newRow, ServiceOrderRelated);
            }
        }
 public FSProfitability(FSAppointmentDetService fsAppointmentDetServiceRow)
 {
     this.LineRef         = fsAppointmentDetServiceRow.LineRef;
     this.LineType        = fsAppointmentDetServiceRow.LineType;
     this.ItemID          = fsAppointmentDetServiceRow.InventoryID;
     this.Descr           = fsAppointmentDetServiceRow.TranDesc;
     this.UnitPrice       = fsAppointmentDetServiceRow.CuryUnitPrice;
     this.EstimatedQty    = fsAppointmentDetServiceRow.EstimatedQty;
     this.EstimatedAmount = fsAppointmentDetServiceRow.CuryEstimatedTranAmt;
     this.ActualDuration  = fsAppointmentDetServiceRow.ActualDuration;
     this.ActualQty       = fsAppointmentDetServiceRow.Qty;
     this.ActualAmount    = fsAppointmentDetServiceRow.CuryTranAmt;
     this.BillableQty     = fsAppointmentDetServiceRow.BillableQty;
     this.BillableAmount  = fsAppointmentDetServiceRow.CuryBillableTranAmt;
     this.UnitCost        = fsAppointmentDetServiceRow.CuryUnitCost;
     this.CostTotal       = this.BillableQty * this.UnitCost;
     this.Profit          = this.BillableAmount - this.CostTotal;
     this.ProfitPercent   = this.CostTotal == 0.0m ? 0.0m : (this.Profit / this.CostTotal) * 100;
 }
Beispiel #5
0
        public static void InsertUpdateEPActivityApprove(
            PXGraph graph,
            EmployeeActivitiesEntry graphEmployeeActivitiesEntry,
            FSAppointmentEmployee fsAppointmentEmployeeRow,
            FSAppointment fsAppointmentRow,
            FSServiceOrder fsServiceOrderRow,
            EPActivityApprove epActivityApproveRow,
            TMEPEmployee epEmployeeRow)
        {
            if (epActivityApproveRow != null &&
                (epActivityApproveRow.ApprovalStatus == ActivityStatusListAttribute.Approved || epActivityApproveRow.TimeCardCD != null))
            {
                return;
            }

            FSAppointmentDetService fsAppointmentDetServiceRow =
                PXSelectJoin <FSAppointmentDetService,
                              InnerJoin <FSSODet,
                                         On <FSSODet.sODetID, Equal <FSAppointmentDetService.sODetID> > >,
                              Where <
                                  FSSODet.lineRef, Equal <Required <FSSODet.lineRef> >,
                                  And <FSSODet.sOID, Equal <Required <FSAppointment.sOID> > > > >
                .Select(graph, fsAppointmentEmployeeRow.ServiceLineRef, fsAppointmentRow.SOID);

            if (fsAppointmentDetServiceRow != null &&
                fsAppointmentDetServiceRow.Status == ID.Status_AppointmentDet.CANCELED)
            {
                return;
            }

            if (epActivityApproveRow == null)
            {
                epActivityApproveRow         = new EPActivityApprove();
                epActivityApproveRow.OwnerID = epEmployeeRow.PKID;
                epActivityApproveRow         = graphEmployeeActivitiesEntry.Activity.Insert(epActivityApproveRow);
            }

            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.hold>(epActivityApproveRow, false);
            epActivityApproveRow.Date          = SharedFunctions.GetCustomDateTime(fsAppointmentRow.ExecutionDate, fsAppointmentEmployeeRow.ActualDateTimeBegin);
            epActivityApproveRow.EarningTypeID = fsAppointmentEmployeeRow.EarningType;
            epActivityApproveRow.TimeSpent     = fsAppointmentEmployeeRow.ActualDuration;
            epActivityApproveRow.Summary       = GetDescriptionToUseInEPActivityApprove(fsAppointmentRow, fsAppointmentEmployeeRow, fsAppointmentDetServiceRow);
            epActivityApproveRow.CostCodeID    = fsAppointmentEmployeeRow?.CostCodeID;

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

            fsxPMTimeActivityRow.SOID                  = fsAppointmentRow.SOID;
            fsxPMTimeActivityRow.AppointmentID         = fsAppointmentRow.AppointmentID;
            fsxPMTimeActivityRow.AppointmentCustomerID = fsServiceOrderRow.CustomerID;
            fsxPMTimeActivityRow.AppEmpID              = fsAppointmentEmployeeRow.LineNbr;

            if (fsAppointmentEmployeeRow.ServiceLineRef != null)
            {
                fsxPMTimeActivityRow.ServiceID = fsAppointmentDetServiceRow == null ? null : fsAppointmentDetServiceRow.InventoryID;
            }

            epActivityApproveRow = graphEmployeeActivitiesEntry.Activity.Update(epActivityApproveRow);

            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.projectID>(epActivityApproveRow, fsServiceOrderRow.ProjectID);
            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.projectTaskID>(epActivityApproveRow, GetProjectTaskIDToUseInEPActivityApprove(fsAppointmentRow, fsAppointmentEmployeeRow, fsAppointmentDetServiceRow));
            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.isBillable>(epActivityApproveRow, false);
            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.approvalStatus>(epActivityApproveRow, GetStatusToUseInEPActivityApprove());
            graphEmployeeActivitiesEntry.Activity.SetValueExt <EPActivityApprove.labourItemID>(epActivityApproveRow, fsAppointmentEmployeeRow.LaborItemID);

            graphEmployeeActivitiesEntry.Save.Press();
        }
Beispiel #6
0
        /// <summary>
        /// Create an Appointment from a TimeSlot.
        /// </summary>
        protected void createAppointment(
            FSServiceOrder fsServiceOrderRow,
            TimeSlot timeSlotAppointment,
            FSSchedule fsScheduleRow,
            bool insertingFromServiceOrder,
            bool isARouteAppointment,
            bool isPrepaidContract)
        {
            if (graphAppointmentEntry != null)
            {
                graphAppointmentEntry.Clear(PXClearOption.ClearAll);
            }
            else
            {
                graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>();
                graphAppointmentEntry.CalculateGoogleStats                = false;
                graphAppointmentEntry.AvoidCalculateRouteStats            = true;
                graphAppointmentEntry.IsGeneratingAppointment             = true;
                graphAppointmentEntry.DisableServiceOrderUnboundFieldCalc = true;
            }

            graphAppointmentEntry.SkipManualTimeFlagUpdate = true;

            FSScheduleRoute fsScheduleRouteRow = null;

            if (isARouteAppointment == true)
            {
                fsScheduleRouteRow =
                    PXSelect <FSScheduleRoute,
                              Where <
                                  FSScheduleRoute.scheduleID, Equal <Required <FSScheduleRoute.scheduleID> > > >
                    .Select(this, fsServiceOrderRow.ScheduleID);
            }

            FSAppointment fsAppointmentRow = new FSAppointment();

            fsAppointmentRow.SrvOrdType = fsServiceOrderRow.SrvOrdType;

            #region Setting flags for recurring appointments
            fsAppointmentRow.ValidatedByDispatcher = false;
            fsAppointmentRow.GeneratedBySystem     = true;
            fsAppointmentRow.Status = ID.Status_Appointment.AUTOMATIC_SCHEDULED;

            fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Insert(fsAppointmentRow);

            graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.soRefNbr>(graphAppointmentEntry.AppointmentRecords.Current, fsServiceOrderRow.RefNbr);
            graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.docDesc>(fsAppointmentRow, fsServiceOrderRow.DocDesc);

            if (isARouteAppointment)
            {
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeBegin>(fsAppointmentRow, timeSlotAppointment.DateTimeBegin);
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeEnd>(fsAppointmentRow, timeSlotAppointment.DateTimeEnd);
            }
            else
            {
                DateTime?scheduledDateTimeBegin = SharedFunctions.GetCustomDateTime(timeSlotAppointment.DateTimeBegin, fsScheduleRow.ScheduleStartTime);
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.scheduledDateTimeBegin>(fsAppointmentRow, scheduledDateTimeBegin);
            }

            graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.serviceContractID>(fsAppointmentRow, fsServiceOrderRow.ServiceContractID);

            if (isPrepaidContract == true &&
                graphAppointmentEntry.BillingCycleRelated.Current != null &&
                graphAppointmentEntry.BillingCycleRelated.Current.BillingBy == ID.Billing_By.APPOINTMENT)
            {
                graphAppointmentEntry.AppointmentRecords.Cache.SetValueExt <FSAppointment.billServiceContractID>(fsAppointmentRow, fsServiceOrderRow.ServiceContractID);
            }

            fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current;

            //Total times get initialized
            fsAppointmentRow.EstimatedDurationTotal = 0;
            fsAppointmentRow.ActualDurationTotal    = 0;

            fsAppointmentRow.ScheduleID        = fsServiceOrderRow.ScheduleID;
            fsAppointmentRow.ServiceContractID = fsServiceOrderRow.ServiceContractID;
            fsAppointmentRow.GenerationID      = fsServiceOrderRow.GenerationID;

            fsAppointmentRow.SalesPersonID  = fsServiceOrderRow.SalesPersonID;
            fsAppointmentRow.Commissionable = fsServiceOrderRow.Commissionable;
            #endregion

            #region Setting route
            if (fsScheduleRouteRow != null)
            {
                switch (timeSlotAppointment.DateTimeBegin.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    if (fsScheduleRouteRow.RouteIDSunday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDSunday;
                    }

                    break;

                case DayOfWeek.Monday:
                    if (fsScheduleRouteRow.RouteIDMonday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDMonday;
                    }

                    break;

                case DayOfWeek.Tuesday:
                    if (fsScheduleRouteRow.RouteIDTuesday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDTuesday;
                    }

                    break;

                case DayOfWeek.Wednesday:
                    if (fsScheduleRouteRow.RouteIDWednesday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDWednesday;
                    }

                    break;

                case DayOfWeek.Thursday:
                    if (fsScheduleRouteRow.RouteIDThursday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDThursday;
                    }

                    break;

                case DayOfWeek.Friday:
                    if (fsScheduleRouteRow.RouteIDFriday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDFriday;
                    }

                    break;

                case DayOfWeek.Saturday:
                    if (fsScheduleRouteRow.RouteIDSaturday != null)
                    {
                        fsAppointmentRow.RouteID = fsScheduleRouteRow.RouteIDSaturday;
                    }

                    break;
                }

                if (fsAppointmentRow.RouteID == null)
                {
                    fsAppointmentRow.RouteID = fsScheduleRouteRow.DfltRouteID;
                }

                fsAppointmentRow.RoutePosition = int.Parse(fsScheduleRouteRow.GlobalSequence);

                if (fsAppointmentRow.DeliveryNotes == null)
                {
                    fsAppointmentRow.DeliveryNotes = fsScheduleRouteRow.DeliveryNotes;
                }
            }
            #endregion

            #region Setting Appointment Details

            foreach (FSSODetService fsSODetRow in graphServiceOrderEntry.ServiceOrderDetServices.Select())
            {
                var fsAppointmentDetRow = new FSAppointmentDetService();

                fsAppointmentDetRow.ScheduleID    = fsSODetRow.ScheduleID;
                fsAppointmentDetRow.ScheduleDetID = fsSODetRow.ScheduleDetID;

                AppointmentEntry.InsertServicePartLine <FSAppointmentDetService, FSSODetService>(
                    graphAppointmentEntry.AppointmentDetServices.Cache,
                    fsAppointmentDetRow,
                    graphServiceOrderEntry.ServiceOrderDetServices.Cache,
                    fsSODetRow,
                    fsSODetRow.NoteID,
                    fsSODetRow.SODetID,
                    copyTranDate: false,
                    tranDate: fsSODetRow.TranDate,
                    SetValuesAfterAssigningSODetID: false,
                    copyingFromQuote: false);
            }

            foreach (FSSODetPart fsSODetRow in graphServiceOrderEntry.ServiceOrderDetParts.Select())
            {
                var fsAppointmentDetRow = new FSAppointmentDetPart();

                fsAppointmentDetRow.ScheduleID    = fsSODetRow.ScheduleID;
                fsAppointmentDetRow.ScheduleDetID = fsSODetRow.ScheduleDetID;

                AppointmentEntry.InsertServicePartLine <FSAppointmentDetPart, FSSODetPart>(
                    graphAppointmentEntry.AppointmentDetParts.Cache,
                    fsAppointmentDetRow,
                    graphServiceOrderEntry.ServiceOrderDetParts.Cache,
                    fsSODetRow,
                    fsSODetRow.NoteID,
                    fsSODetRow.SODetID,
                    copyTranDate: false,
                    tranDate: fsSODetRow.TranDate,
                    SetValuesAfterAssigningSODetID: false,
                    copyingFromQuote: false);
            }

            foreach (FSSOEmployee fsSOEmployeeRow in graphServiceOrderEntry.ServiceOrderEmployees.Select())
            {
                FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee();
                fsAppointmentEmployeeRow.EmployeeID = fsSOEmployeeRow.EmployeeID;
                graphAppointmentEntry.AppointmentEmployees.Insert(fsAppointmentEmployeeRow);
            }
            #endregion

            if (fsScheduleRow.VendorID != null)
            {
                FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee();
                fsAppointmentEmployeeRow.EmployeeID = fsScheduleRow.VendorID;
                graphAppointmentEntry.AppointmentEmployees.Insert(fsAppointmentEmployeeRow);
            }

            if (insertingFromServiceOrder == true)
            {
                graphAppointmentEntry.SkipServiceOrderUpdate = true;
            }

            try
            {
                graphAppointmentEntry.Save.Press();
            }
            finally
            {
                graphAppointmentEntry.SkipServiceOrderUpdate = false;
            }
        }