public virtual void PrimaryDriver_FieldUpdated_Handler(PXCache cache, FSAppointmentEmployee fsAppointmentEmployeeRow) { PXResultset <FSAppointmentEmployee> employeeRows = AppointmentServiceEmployees.Select(); foreach (FSAppointmentEmployee row in employeeRows.RowCast <FSAppointmentEmployee>() .Where(_ => _.EmployeeID == fsAppointmentEmployeeRow.EmployeeID)) { row.PrimaryDriver = fsAppointmentEmployeeRow.PrimaryDriver; if (cache.GetStatus(row) == PXEntryStatus.Notchanged) { cache.SetStatus(row, PXEntryStatus.Updated); } } if (fsAppointmentEmployeeRow.PrimaryDriver == true) { foreach (FSAppointmentEmployee row in employeeRows.RowCast <FSAppointmentEmployee>() .Where(_ => _.EmployeeID != fsAppointmentEmployeeRow.EmployeeID && _.PrimaryDriver == true)) { row.PrimaryDriver = false; if (cache.GetStatus(row) == PXEntryStatus.Notchanged) { cache.SetStatus(row, PXEntryStatus.Updated); } } } AppointmentServiceEmployees.View.RequestRefresh(); }
public FSProfitability(FSAppointmentEmployee fsAppointmentEmployeeRow) { this.LineRef = fsAppointmentEmployeeRow.LineRef; this.LineType = ID.LineType_Profitability.LABOR_ITEM; this.ItemID = fsAppointmentEmployeeRow.LaborItemID; this.EmployeeID = fsAppointmentEmployeeRow.EmployeeID; this.ActualDuration = fsAppointmentEmployeeRow.ActualDuration; this.ActualQty = ((decimal)fsAppointmentEmployeeRow.ActualDuration) / 60m; this.UnitCost = fsAppointmentEmployeeRow.CuryUnitCost; this.CostTotal = fsAppointmentEmployeeRow.CuryExtCost; }
public static void FindEPActivityApprove( PXGraph graph, FSAppointmentEmployee fsAppointmentEmployeeRow, TMEPEmployee epEmployeeRow, ref EPActivityApprove epActivityApproveRow) { epActivityApproveRow = PXSelect <EPActivityApprove, Where < EPActivityApprove.ownerID, Equal <Required <EPActivityApprove.ownerID> >, And <FSxPMTimeActivity.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> >, And <FSxPMTimeActivity.appEmpID, Equal <Required <FSAppointmentEmployee.lineNbr> > > > > > .Select(graph, epEmployeeRow.PKID, fsAppointmentEmployeeRow.AppointmentID, fsAppointmentEmployeeRow.LineNbr); }
public virtual void CloneEmployees(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment, FSAppointment newFSAppointmentRow) { foreach (FSAppointmentEmployee originalAppointmentEmployee in graphOriginalAppointment.AppointmentServiceEmployees.Select()) { FSAppointmentEmployee fsAppointmentEmployeeRow = PXCache <FSAppointmentEmployee> .CreateCopy(originalAppointmentEmployee); fsAppointmentEmployeeRow.AppointmentID = newFSAppointmentRow.AppointmentID; fsAppointmentEmployeeRow.RefNbr = null; fsAppointmentEmployeeRow.NoteID = null; graphNewAppointment.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); } }
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(); } } }
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); } }
private void InsertEmployeeLinkedToService(AppointmentEntry graphAppointmentEntry, List <string> employeeList, string lineRef) { foreach (string employeeID in employeeList) { int employeeIntID = -1; if (int.TryParse(employeeID, out employeeIntID)) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee(); fsAppointmentEmployeeRow.EmployeeID = employeeIntID; fsAppointmentEmployeeRow.ServiceLineRef = lineRef; graphAppointmentEntry.AppointmentEmployees.Insert(fsAppointmentEmployeeRow); } } }
private static int?GetTimeSpentToUseInEPActivityApprove( FSAppointment fsAppointmentRow, FSAppointmentEmployee fsAppointmentEmployeeRow) { if (fsAppointmentEmployeeRow != null && fsAppointmentEmployeeRow.ServiceLineRef != null) { return(fsAppointmentEmployeeRow.ActualDuration); } else { return((int?)(fsAppointmentRow.ActualDateTimeEnd - fsAppointmentRow.ActualDateTimeBegin).Value.TotalMinutes); } }
/// <summary> /// Reassign the selected appointment <c>RefNbr</c> to the selected RouteDocumentID from the SmartPanel. /// </summary> /// <param name="fsRouteDocumentRow">New RouteDocumentID where the appointment is going to be assigned.</param> /// <param name="refNbr"><c>RefNbr</c> of the appointment to be assigned.</param> /// <param name="srvOrdType"><c>SrvOrdType</c> of the appointment to be assigned.</param> public static void ReassignAppointmentToRoute(FSRouteDocument fsRouteDocumentRow, string refNbr, string srvOrdType) { using (PXTransactionScope ts = new PXTransactionScope()) { var graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>(); FSAppointment fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.refNbr>(refNbr, srvOrdType); int?originalRouteDocumentID = fsAppointmentRow.RouteDocumentID; int?originalAppointmentPosition = fsAppointmentRow.RoutePosition; fsAppointmentRow.RoutePosition = null; if (fsRouteDocumentRow != null) { fsAppointmentRow.RouteID = fsRouteDocumentRow.RouteID; fsAppointmentRow.RouteDocumentID = fsRouteDocumentRow.RouteDocumentID; fsAppointmentRow.ScheduledDateTimeBegin = fsRouteDocumentRow.TimeBegin != null ? fsRouteDocumentRow.TimeBegin : fsRouteDocumentRow.Date; } else { fsAppointmentRow.RouteID = null; fsAppointmentRow.RouteDocumentID = null; //Clear vehicle and driver if exist fsAppointmentRow.VehicleID = null; FSAppointmentEmployee fsAppointmentEmployeeRow = PXSelect <FSAppointmentEmployee, Where < FSAppointmentEmployee.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> >, And < FSAppointmentEmployee.isDriver, Equal <True> > > > .Select(graphAppointmentEntry, fsAppointmentRow.AppointmentID); if (fsAppointmentEmployeeRow != null) { graphAppointmentEntry.AppointmentServiceEmployees.Delete(fsAppointmentEmployeeRow); } } fsAppointmentRow.IsReassigned = true; graphAppointmentEntry.AppointmentRecords.Update(fsAppointmentRow); graphAppointmentEntry.SelectTimeStamp(); graphAppointmentEntry.Save.Press(); ReassignAppointmentPositionsInRoute(originalRouteDocumentID, originalAppointmentPosition); ts.Complete(); } }
private static DateTime?GetDateToUseInEPActivityApprove( FSAppointment fsAppointmentRow, FSAppointmentEmployee fsAppointmentEmployeeRow) { if (fsAppointmentEmployeeRow != null && fsAppointmentEmployeeRow.ServiceLineRef != null && fsAppointmentEmployeeRow.ActualDateTimeBegin != null) { return(SharedFunctions.GetCustomDateTime(fsAppointmentRow.ExecutionDate, fsAppointmentEmployeeRow.ActualDateTimeBegin)); } else { return(SharedFunctions.GetCustomDateTime(fsAppointmentRow.ExecutionDate, fsAppointmentRow.ActualDateTimeBegin)); } }
private void CloneEmployees(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment, FSAppointment newFSAppointmentRow) { foreach (FSAppointmentEmployee originalAppointmentEmployee in graphOriginalAppointment.AppointmentEmployees.Select()) { FSAppointmentEmployee fsAppointmentEmployeeRow = PXCache <FSAppointmentEmployee> .CreateCopy(originalAppointmentEmployee); fsAppointmentEmployeeRow.AppointmentID = newFSAppointmentRow.AppointmentID; fsAppointmentEmployeeRow.RefNbr = null; fsAppointmentEmployeeRow.ActualDuration = null; fsAppointmentEmployeeRow.ActualDateTimeBegin = null; fsAppointmentEmployeeRow.ActualDateTimeEnd = null; graphNewAppointment.AppointmentEmployees.Insert(fsAppointmentEmployeeRow); } }
public static void AssignAppointmentEmployeeByList(AppointmentEntry graphAppointmentEntry, List <string> employeeList, List <string> soDetIDList) { employeeList.Reverse(); if (employeeList.Count > 0 && soDetIDList.Count <= 0) { for (int i = 0; i < employeeList.Count; i++) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee(); fsAppointmentEmployeeRow = graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); graphAppointmentEntry.AppointmentServiceEmployees.Cache.SetValueExt <FSAppointmentEmployee.employeeID>(fsAppointmentEmployeeRow, (int?)Convert.ToInt32(employeeList[i])); } } }
private static void SearchAndDeleteEPActivity( AppointmentEntry graphAppointmentEntry, FSAppointmentEmployee fsAppointmentEmployee, EmployeeActivitiesEntry graphEmployeeActivitiesEntry) { EPActivityApprove epActivityApproveRow = null; TMEPEmployee epEmployeeRow = null; FindTMEmployee(graphAppointmentEntry, fsAppointmentEmployee.EmployeeID, ref epEmployeeRow); FindEPActivityApprove(graphAppointmentEntry, fsAppointmentEmployee, epEmployeeRow, ref epActivityApproveRow); if (epActivityApproveRow != null) { DeleteEPActivityApprove(graphEmployeeActivitiesEntry, epActivityApproveRow); } }
private static void InsertEmployeeLinkedToService(AppointmentEntry graphAppointmentEntry, List <string> employeeList, string lineRef) { foreach (string employeeID in employeeList) { int employeeIntID = -1; if (int.TryParse(employeeID, out employeeIntID)) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee(); fsAppointmentEmployeeRow = graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); graphAppointmentEntry.AppointmentServiceEmployees.Cache.SetValueExt <FSAppointmentEmployee.employeeID>(fsAppointmentEmployeeRow, employeeIntID); graphAppointmentEntry.AppointmentServiceEmployees.Cache.SetValueExt <FSAppointmentEmployee.serviceLineRef>(fsAppointmentEmployeeRow, lineRef); } } }
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); } }
/// <summary> /// Add the Vendor(s) info as a recipient(s) in the Email template generated by Appointment. /// </summary> private static void AddVendorStaffRecipient(AppointmentEntry graphAppointmentEntry, FSAppointmentEmployee fsAppointmentEmployee, NotificationRecipient recSetup, RecipientList recipients) { //TODO: AC-142850 6082 validate Vendor's AppNotification flag /* * select * from Contact * inner join BAccount on (BAccount.BAccountID = Contact.BAccountID * and BAccount.DefContactID = Contact.ContactID) * where * BAccount.BAccountID = xx * and BAccount.Type = 'VE' */ //BAccountType.VendorType }
public virtual void CloneEmployees(AppointmentEntry graphOriginalAppointment, AppointmentEntry graphNewAppointment, FSAppointment newFSAppointmentRow, Dictionary <string, string> itemLineRef) { foreach (FSAppointmentEmployee originalAppointmentEmployee in graphOriginalAppointment.AppointmentServiceEmployees.Select()) { FSAppointmentEmployee fsAppointmentEmployeeRow = PXCache <FSAppointmentEmployee> .CreateCopy(originalAppointmentEmployee); fsAppointmentEmployeeRow.AppointmentID = newFSAppointmentRow.AppointmentID; fsAppointmentEmployeeRow.RefNbr = null; fsAppointmentEmployeeRow.NoteID = null; if (string.IsNullOrEmpty(fsAppointmentEmployeeRow.ServiceLineRef) == false && itemLineRef.ContainsKey(fsAppointmentEmployeeRow.ServiceLineRef) == true) { fsAppointmentEmployeeRow.ServiceLineRef = itemLineRef[fsAppointmentEmployeeRow.ServiceLineRef]; } graphNewAppointment.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); } }
/// <summary> /// Launches the AppointmentEntry screen with some preloaded values. /// </summary> /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param> public static void AssignAppointmentEmployee(FSAppointmentScheduleBoard fsAppointmentRow, ExternalControls graphExternalControls, AppointmentEntry graphAppointmentMaint, ref ExternalControls.DispatchBoardAppointmentMessages response) { FSServiceOrder fsServiceOrderRow = graphAppointmentMaint.ServiceOrderRelated.Current; if (string.IsNullOrEmpty(fsAppointmentRow.RoomID) == false && string.IsNullOrWhiteSpace(fsAppointmentRow.RoomID) == false) { fsServiceOrderRow.RoomID = fsAppointmentRow.RoomID; } graphAppointmentMaint.ServiceOrderRelated.Update(fsServiceOrderRow); if (fsAppointmentRow.OldEmployeeID != fsAppointmentRow.EmployeeID) { FSAppointmentEmployee fsAppointmentEmployeeRow = graphExternalControls.AppointmentEmployeeByEmployee .Select(fsAppointmentRow.AppointmentID, fsAppointmentRow.EmployeeID); if (fsAppointmentEmployeeRow != null) { response.ErrorMessages.Add(ExternalControls.GetErrorMessage(ExternalControls.ErrorCode.APPOINTMENT_SHARED)); } else { FSAppointmentEmployee fsAppointmentEmployeeRow_New = new FSAppointmentEmployee() { AppointmentID = fsAppointmentRow.AppointmentID, EmployeeID = fsAppointmentRow.EmployeeID }; fsAppointmentEmployeeRow_New = graphAppointmentMaint.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow_New); foreach (FSAppointmentEmployee fsAppointmentEmployeeRow_Old in graphAppointmentMaint.AppointmentServiceEmployees.Select()) { if (fsAppointmentEmployeeRow_Old.EmployeeID == fsAppointmentRow.OldEmployeeID) { graphAppointmentMaint.AppointmentServiceEmployees.Delete(fsAppointmentEmployeeRow_Old); } } } } }
public virtual void PrimaryDriver_RowDeleting_Handler(PXCache cache, FSAppointmentEmployee fsAppointmentEmployeeRow) { if (fsAppointmentEmployeeRow.PrimaryDriver == true) { PXResultset <FSAppointmentEmployee> fsAppointmentEmployeeRows = AppointmentServiceEmployees.Select(); if (fsAppointmentEmployeeRows.RowCast <FSAppointmentEmployee>() .Where(_ => _.EmployeeID == fsAppointmentEmployeeRow.EmployeeID).Any() == false) { IEnumerable <FSAppointmentEmployee> firstAppointmentEmployeeRow = fsAppointmentEmployeeRows.RowCast <FSAppointmentEmployee>() .OrderBy(_ => _.LineNbr); if (firstAppointmentEmployeeRow.Any() == true) { cache.SetValueExt <FSAppointmentEmployee.primaryDriver>(firstAppointmentEmployeeRow.First(), true); } AppointmentRecords.Current.PrimaryDriver = firstAppointmentEmployeeRow.FirstOrDefault()?.EmployeeID; } } }
/// <summary> /// Update ApprovedTime and actualDuration fields in the <c>AppointmentDetInfo</c> lines. /// </summary> private void UpdateAppointmentFromApprovedTimeCard(PXCache cache) { FSxPMTimeActivity fsxPMTimeActivityRow = null; var graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>(); foreach (TimeCardMaint.EPTimecardDetail ePTimeCardDetailRow in this.Base.Activities.Select()) { fsxPMTimeActivityRow = this.Base.Activities.Cache.GetExtension <FSxPMTimeActivity>(ePTimeCardDetailRow); if (fsxPMTimeActivityRow.AppEmpID.HasValue == false) { continue; } FSAppointment fsAppointmentRow = PXSelect <FSAppointment, Where < FSAppointment.appointmentID, Equal <Required <FSAppointment.appointmentID> > > > .Select(Base, fsxPMTimeActivityRow.AppointmentID); FSAppointmentEmployee fsAppointmentEmployeeRow = PXSelect <FSAppointmentEmployee, Where < FSAppointmentEmployee.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> >, And <FSAppointmentEmployee.lineNbr, Equal <Required <FSAppointmentEmployee.lineNbr> > > > > .Select(Base, fsxPMTimeActivityRow.AppointmentID, fsxPMTimeActivityRow.AppEmpID); graphAppointmentEntry.SkipTimeCardUpdate = true; fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.appointmentID> (fsAppointmentRow.AppointmentID, fsAppointmentRow.SrvOrdType); fsAppointmentEmployeeRow.TimeCardCD = ePTimeCardDetailRow.TimeCardCD; fsAppointmentEmployeeRow.ApprovedTime = true; fsAppointmentEmployeeRow = graphAppointmentEntry.AppointmentEmployees.Update(fsAppointmentEmployeeRow); graphAppointmentEntry.Save.Press(); } }
/// <summary> /// Gets the employees contact info separated by a coma. /// </summary> /// <param name="graph">Graph to use.</param> /// <param name="concatenateNames">Boolean that if true, returns the Staff name(s).</param> /// <param name="concatenateCells">Boolean that if true, returns the Staff cell phone(s).</param> /// <param name="appointmentID">Appointment ID.</param> private static StringBuilder GetsEmployeesContactInfo(PXGraph graph, bool concatenateNames, bool concatenateCells, int?appointmentID) { StringBuilder names = new StringBuilder(); int i = 0; // TODO SD-7612 this BQL is not currently retrieving contact info for vendors BqlCommand fsAppointmentEmployeeContactInfoBql = new Select5 <FSAppointmentEmployee, InnerJoin <BAccount, On < BAccount.bAccountID, Equal <FSAppointmentEmployee.employeeID> >, InnerJoin <Contact, On < BAccount.defContactID, Equal <Contact.contactID> > > >, Where < FSAppointmentEmployee.appointmentID, Equal <Required <FSAppointmentEmployee.appointmentID> > >, Aggregate < GroupBy <FSAppointmentEmployee.employeeID> >, OrderBy < Asc <FSAppointmentEmployee.employeeID> > >(); PXView fsAppointmentEmployeeContactInfoView = new PXView(graph, true, fsAppointmentEmployeeContactInfoBql); var fsAppointmentEmployeeSet = fsAppointmentEmployeeContactInfoView.SelectMulti(appointmentID); if (fsAppointmentEmployeeSet.Count > 0) { foreach (PXResult <FSAppointmentEmployee, BAccount, Contact> bqlResult in fsAppointmentEmployeeSet) { FSAppointmentEmployee fsAppointmentEmployeeRow = (FSAppointmentEmployee)bqlResult; BAccount bAccountRow = (BAccount)bqlResult; Contact contactRow = (Contact)bqlResult; i++; if (fsAppointmentEmployeeSet.Count > 1 && i == fsAppointmentEmployeeSet.Count) { names.Append(PXMessages.LocalizeFormatNoPrefix(TX.Messages.LIST_LAST_ITEM_PREFIX)); } else { if (names.Length != 0) { names.Append(", "); } } if (fsAppointmentEmployeeRow.Type == BAccountType.EmployeeType) { if (string.IsNullOrEmpty(contactRow.FirstName) == false && concatenateNames == true) { names.Append(contactRow.FirstName.Trim()); } if (string.IsNullOrEmpty(contactRow.LastName) == false && concatenateNames == true) { names.Append(' '); names.Append(contactRow.LastName.Trim()); } } else if (fsAppointmentEmployeeRow.Type == BAccountType.VendorType) { if (string.IsNullOrEmpty(contactRow.FullName) == false && concatenateNames == true) { names.Append(contactRow.FullName.Trim()); } } if (string.IsNullOrEmpty(contactRow.Phone1) == false && concatenateCells == true) { names.Append(contactRow.Phone1.Trim()); } else if (concatenateCells == true) { names.Append(TX.Messages.NO_CONTACT_CELL_FOR_THE_STAFF); } } } else { names.Append(TX.Messages.NO_STAFF_ASSIGNED_FOR_THE_APPOINTMENT); } return(names); }
/// <summary> /// Launches the AppointmentEntry screen with some preloaded values. /// </summary> /// <param name="fsWrkProcessRow"><c>FSWrkProcess</c> row.</param> private void LaunchAppointmentEntryScreen(FSWrkProcess fsWrkProcessRow) { AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>(); FSAppointment fsAppointmentRow = new FSAppointment(); FSServiceOrder fsServiceOrderRow = GetServiceOrder(fsWrkProcessRow); fsAppointmentRow.SrvOrdType = GetSrvOrdType(fsWrkProcessRow, fsServiceOrderRow); if (fsAppointmentRow.SrvOrdType == null) { throw new PXException(TX.Error.DEFAULT_SERVICE_ORDER_TYPE_NOT_PROVIDED); } if (fsAppointmentRow.SOID == null) { SharedFunctions.ValidateSrvOrdTypeNumberingSequence(this, fsAppointmentRow.SrvOrdType); } graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Insert(fsAppointmentRow); #region ScheduleDateTime Fields // to know if we want to set false to the flag KeepTotalServicesDuration bool scheduleTimeFlag = true; if (fsWrkProcessRow.ScheduledDateTimeBegin.HasValue == true) { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeBegin> (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeBegin); } else { scheduleTimeFlag = false; } if (fsWrkProcessRow.ScheduledDateTimeEnd.HasValue && scheduleTimeFlag) { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.handleManuallyScheduleTime> (graphAppointmentEntry.AppointmentRecords.Current, true); if (fsWrkProcessRow.ScheduledDateTimeBegin != fsWrkProcessRow.ScheduledDateTimeEnd) { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeEnd> (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeEnd); } else { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.scheduledDateTimeEnd> (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.ScheduledDateTimeBegin.Value.AddHours(1)); } } #endregion #region ServiceOrder Fields if (fsServiceOrderRow == null) { if (fsWrkProcessRow.BranchID.HasValue == true) { graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.branchID> (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.BranchID); } if (fsWrkProcessRow.BranchLocationID.HasValue == true && fsWrkProcessRow.BranchLocationID > 0) { graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.branchLocationID> (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.BranchLocationID); } if (fsWrkProcessRow.CustomerID.HasValue == true && fsWrkProcessRow.CustomerID > 0) { graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.customerID> (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.CustomerID); } } else { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.soRefNbr> (graphAppointmentEntry.AppointmentRecords.Current, fsServiceOrderRow.RefNbr); } if (string.IsNullOrEmpty(fsWrkProcessRow.RoomID) == false && string.IsNullOrWhiteSpace(fsWrkProcessRow.RoomID) == false) { graphAppointmentEntry.ServiceOrderRelated.SetValueExt <FSServiceOrder.roomID> (graphAppointmentEntry.ServiceOrderRelated.Current, fsWrkProcessRow.RoomID); if (fsServiceOrderRow != null) { graphAppointmentEntry.ServiceOrderRelated.Cache.SetStatus(graphAppointmentEntry.ServiceOrderRelated.Current, PXEntryStatus.Updated); } } #endregion #region Get Appointment Values List <string> soDetIDList = GetParameterList(fsWrkProcessRow.LineRefList, SEPARATOR); List <string> employeeList = GetParameterList(fsWrkProcessRow.EmployeeIDList, SEPARATOR); #region Services soDetIDList.Reverse(); if (soDetIDList.Count > 0) { foreach (FSAppointmentDetService fsAppointmentDetServiceRow in graphAppointmentEntry.AppointmentDetServices.Select()) { if (soDetIDList.Contains(fsAppointmentDetServiceRow.SODetID.ToString()) == false) { graphAppointmentEntry.AppointmentDetServices.Delete(fsAppointmentDetServiceRow); } else { InsertEmployeeLinkedToService(graphAppointmentEntry, employeeList, fsAppointmentDetServiceRow.LineRef); } } foreach (FSAppointmentEmployee fsAppointmentEmployeeRow in graphAppointmentEntry.AppointmentEmployees.Select() .RowCast <FSAppointmentEmployee>() .Where(_ => _.ServiceLineRef != null)) { FSAppointmentDet fsAppointmentDetRow = (FSAppointmentDet)PXSelectorAttribute.Select <FSAppointmentEmployee.serviceLineRef> (graphAppointmentEntry.AppointmentEmployees.Cache, fsAppointmentEmployeeRow); if (fsAppointmentDetRow != null && soDetIDList.Contains(fsAppointmentDetRow.SODetID.ToString()) == false) { graphAppointmentEntry.AppointmentEmployees.Delete(fsAppointmentEmployeeRow); } } } #endregion #region Employees employeeList.Reverse(); if (employeeList.Count > 0 && soDetIDList.Count <= 0) { for (int i = 0; i < employeeList.Count; i++) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee(); fsAppointmentEmployeeRow.EmployeeID = (int?)Convert.ToInt32(employeeList[i]); graphAppointmentEntry.AppointmentEmployees.Insert(fsAppointmentEmployeeRow); } } #endregion #region Equipment List <string> equipmentList = GetParameterList(fsWrkProcessRow.EquipmentIDList, SEPARATOR); equipmentList.Reverse(); if (equipmentList.Count > 0) { for (int i = 0; i < equipmentList.Count; i++) { FSAppointmentResource fsAppointmentResourceRow = new FSAppointmentResource(); fsAppointmentResourceRow.SMEquipmentID = (int?)Convert.ToInt32(equipmentList[i]); graphAppointmentEntry.AppointmentResources.Insert(fsAppointmentResourceRow); } } #endregion #endregion if (fsWrkProcessRow.SMEquipmentID.HasValue == true) { graphAppointmentEntry.AppointmentRecords.SetValueExt <FSAppointment.mem_SMequipmentID> (graphAppointmentEntry.AppointmentRecords.Current, fsWrkProcessRow.SMEquipmentID); } throw new PXRedirectRequiredException(graphAppointmentEntry, null) { Mode = PXBaseRedirectException.WindowMode.Same }; }
/// <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 = PXDBDateAndTimeAttribute.CombineDateTime(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 (FSSODet fsSODetRow in graphServiceOrderEntry.ServiceOrderDetails.Select()) { var fsAppointmentDetRow = new FSAppointmentDet(); fsAppointmentDetRow.ScheduleID = fsSODetRow.ScheduleID; fsAppointmentDetRow.ScheduleDetID = fsSODetRow.ScheduleDetID; AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSSODet>(graphAppointmentEntry.AppointmentDetails.Cache, fsAppointmentDetRow, graphServiceOrderEntry.ServiceOrderDetails.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.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); } #endregion if (fsScheduleRow.VendorID != null) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee(); fsAppointmentEmployeeRow.EmployeeID = fsScheduleRow.VendorID; graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow); } graphAppointmentEntry.Save.Press(); }
public virtual void StartStaffAction(IEnumerable <FSStaffLogActionDetail> createLogItems = null) { IEnumerable <FSStaffLogActionDetail> createLogItemsLocal = null; if (createLogItems == null) { if (LogActionFilter.Current.Me == true) { EPEmployee employeeByUserID = PXSelect <EPEmployee, Where < EPEmployee.userID, Equal <Current <AccessInfo.userID> > > > .Select(this); if (employeeByUserID != null) { bool isEmployeeInGrid = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>() .Where(x => x.EmployeeID == employeeByUserID.BAccountID) .Count() > 0; bool isTherePrimaryDriver = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>() .Where(x => x.PrimaryDriver == true) .Count() > 0; if (isEmployeeInGrid == false) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee() { EmployeeID = employeeByUserID.BAccountID }; if (isTherePrimaryDriver == false) { fsAppointmentEmployeeRow.PrimaryDriver = true; } AppointmentServiceEmployees.Cache.Insert(fsAppointmentEmployeeRow); FSAppointmentLog fsAppointmentLogRow = new FSAppointmentLog() { Type = ID.Type_Log.STAFF_ASSIGMENT, BAccountID = employeeByUserID.BAccountID, DetLineRef = null, DateTimeBegin = LogActionFilter.Current.LogTime }; LogRecords.Cache.Insert(fsAppointmentLogRow); } else { createLogItemsLocal = LogStaffActionDetails.Select().RowCast <FSStaffLogActionDetail>() .Where(x => x.Selected == true); } } } else { createLogItemsLocal = LogStaffActionDetails.Select().RowCast <FSStaffLogActionDetail>() .Where(x => x.Selected == true); } } else { createLogItemsLocal = createLogItems; } if (createLogItemsLocal != null) { foreach (FSStaffLogActionDetail fsStaffLogActionDetailRow in createLogItemsLocal) { int?timeDuration = fsStaffLogActionDetailRow != null && fsStaffLogActionDetailRow.EstimatedDuration != null ? fsStaffLogActionDetailRow.EstimatedDuration : 0; FSAppointmentLog fsAppointmentLogRow = new FSAppointmentLog() { Type = ID.Type_Log.STAFF_ASSIGMENT, BAccountID = fsStaffLogActionDetailRow.BAccountID, DetLineRef = fsStaffLogActionDetailRow.DetLineRef, DateTimeBegin = LogActionFilter.Current.LogTime, TimeDuration = timeDuration }; LogRecords.Cache.Insert(fsAppointmentLogRow); } } }
public virtual void StartServiceAction(IEnumerable <FSAppointmentEmployeeFSLogStart> createLogItems = null) { IEnumerable <FSAppointmentEmployeeFSLogStart> createLogItemsLocal = null; FSAppointmentLog fsAppointmentLogRow; FSAppointmentDet fsAppointmentDetRow = null; string detLineRef = null; DateTime? dateTimeBegin = null; int timeDuration = 0; if (LogActionFilter.Current?.DetLineRef == null) { return; } if (createLogItems == null) { detLineRef = LogActionFilter.Current?.DetLineRef; dateTimeBegin = LogActionFilter.Current?.LogTime; if (LogActionFilter.Current.DetLineRef != null) { fsAppointmentDetRow = PXSelect <FSAppointmentDet, Where < FSAppointmentDet.appointmentID, Equal <Required <FSAppointmentDet.appointmentID> >, And <FSAppointmentDet.lineRef, Equal <Required <FSAppointmentDet.lineRef> > > > > .Select(this, AppointmentRecords.Current.AppointmentID, LogActionFilter.Current.DetLineRef); if (fsAppointmentDetRow != null) { timeDuration = fsAppointmentDetRow.EstimatedDuration ?? 0; } } if (LogActionFilter.Current.Me == true) { EPEmployee employeeByUserID = PXSelect <EPEmployee, Where < EPEmployee.userID, Equal <Current <AccessInfo.userID> > > > .Select(this); if (employeeByUserID != null) { bool isEmployeeInGrid = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>() .Where(x => x.EmployeeID == employeeByUserID.BAccountID) .Count() > 0; bool isTherePrimaryDriver = AppointmentServiceEmployees.Select().RowCast <FSAppointmentEmployee>() .Where(x => x.PrimaryDriver == true) .Count() > 0; if (isEmployeeInGrid == false) { FSAppointmentEmployee fsAppointmentEmployeeRow = new FSAppointmentEmployee() { EmployeeID = employeeByUserID.BAccountID, }; if (isTherePrimaryDriver == false) { fsAppointmentEmployeeRow.PrimaryDriver = true; } AppointmentServiceEmployees.Cache.Insert(fsAppointmentEmployeeRow); } fsAppointmentLogRow = new FSAppointmentLog() { Type = ID.Type_Log.SERVICE, BAccountID = employeeByUserID.BAccountID, DetLineRef = detLineRef, DateTimeBegin = dateTimeBegin, TimeDuration = timeDuration }; LogRecords.Cache.Insert(fsAppointmentLogRow); } } else { createLogItemsLocal = StaffMemberLogStartAction.Select().RowCast <FSAppointmentEmployeeFSLogStart>() .Where(x => x.Selected == true); } } else { detLineRef = null; dateTimeBegin = PXDBDateAndTimeAttribute.CombineDateTime(AppointmentRecords.Current.ExecutionDate, PXTimeZoneInfo.Now); createLogItemsLocal = createLogItems; } if (createLogItemsLocal != null) { foreach (FSAppointmentEmployeeFSLogStart row in createLogItemsLocal) { fsAppointmentLogRow = new FSAppointmentLog() { Type = ID.Type_Log.SERVICE, BAccountID = row.BAccountID, DetLineRef = detLineRef, DateTimeBegin = dateTimeBegin, TimeDuration = timeDuration }; LogRecords.Cache.Insert(fsAppointmentLogRow); } } }
public virtual void OptimizeRoutes(RoutesOptimizationProcess graph, FSAppointmentFilter filter, List <FSAppointmentFSServiceOrder> list, PXResultset <FSAppointmentStaffMember, CSCalendar> staffSelected) { RouteOptimizerClient client = new RouteOptimizerClient(); SingleDayOptimizationInput requestBody = new SingleDayOptimizationInput(); List <FSAppointment> processList = new List <FSAppointment>(); FSSetup fsSetupRow = graph.SetupRecord.Current; requestBody.balanced = true; requestBody.vehicles = new List <Vehicle>(); requestBody.waypoints = new List <Waypoint>(); string address = string.Empty; if (staffSelected != null && staffSelected.Count == 0) { throw new PXException(PXMessages.LocalizeFormatNoPrefix(TX.Error.SELECT_AT_LEAST_ONE_STAFF_MEMBER)); } //Origin end Route location FSAddress fsAddressRow = PXSelectJoin <FSAddress, InnerJoin <FSBranchLocation, On <FSBranchLocation.branchLocationAddressID, Equal <FSAddress.addressID> > >, Where < FSBranchLocation.branchLocationID, Equal <Required <FSBranchLocation.branchLocationID> > > > .Select(graph, list[0].BranchLocationID); address = SharedFunctions.GetAddressForGeolocation(fsAddressRow.PostalCode, fsAddressRow.AddressLine1, fsAddressRow.AddressLine2, fsAddressRow.City, fsAddressRow.State, fsAddressRow.CountryID); GLocation[] results = Geocoder.Geocode(address, fsSetupRow.MapApiKey); if (results.Length == 0) { throw new PXException(PXMessages.LocalizeFormatNoPrefix(TX.Error.MAPS_FAILED_REVERSE_ADRESS, TX.TableName.BRANCH_LOCATION)); } CSCalendar csVendorCalendarRow = PXSelect <CSCalendar, Where <CSCalendar.calendarID, Equal <Required <CSCalendar.calendarID> > > > .Select(graph, fsSetupRow.CalendarID); //Driver Logic foreach (PXResult <FSAppointmentStaffMember, CSCalendar> result in staffSelected) { FSAppointmentStaffMember staffRow = (FSAppointmentStaffMember)result; CSCalendar csCalendarRow = (CSCalendar)result; Vehicle vehicleRow = new Vehicle() { name = staffRow.BAccountID.ToString(), origin = new RouteLocation() { latitude = results[0].LatLng.Latitude, longitude = results[0].LatLng.Longitude }, destination = new RouteLocation() { latitude = results[0].LatLng.Latitude, longitude = results[0].LatLng.Longitude }, tags = new List <string>() { staffRow.BAccountID.ToString() } }; TimeWindow working = graph.GetWorkingTimeWindow(staffRow.EmployeeSDEnabled == true ? csCalendarRow : csVendorCalendarRow, filter.StartDate); Break lunchBreak = graph.GetBreakWindow(fsSetupRow); if (lunchBreak != null) { vehicleRow.breaks = new List <Break>() { lunchBreak }; } if (working != null) { vehicleRow.timeWindow = working; requestBody.vehicles.Add(vehicleRow); } } if (requestBody.vehicles.Count == 0) { for (int i = 0; i < list.Count; i++) { FSAppointment fsAppointmentRow = list[i]; UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.NOT_ABLE); graph.Appointments.Update(fsAppointmentRow); PXProcessing <FSAppointmentFSServiceOrder> .SetError(i, PXMessages.LocalizeFormatNoPrefix(TX.Error.APPOINTMENT_COULD_NOT_BE_REACH_SERVICED_NO_DRIVER_AVAILABLE)); } if (graph.Appointments.Cache.IsDirty == true) { graph.Appointments.Cache.Persist(PXDBOperation.Update); } return; } //Existing Appointment Logic if (filter.Type == ID.Type_ROOptimization.UNASSIGNED_APP && staffSelected.Count() > 0) { List <object> args = new List <object>(); BqlCommand fsAppointmentList = new Select2 <FSAppointment, InnerJoin <FSServiceOrder, On <FSServiceOrder.sOID, Equal <FSAppointment.sOID> >, InnerJoin <FSAddress, On <FSAddress.addressID, Equal <FSServiceOrder.serviceOrderAddressID> > > > >(); if (filter.BranchID != null) { fsAppointmentList = fsAppointmentList.WhereAnd(typeof(Where <FSServiceOrder.branchID, Equal <Required <FSServiceOrder.branchID> > >)); args.Add(filter.BranchID); } if (filter.BranchLocationID != null) { fsAppointmentList = fsAppointmentList.WhereAnd(typeof(Where <FSServiceOrder.branchLocationID, Equal <Required <FSServiceOrder.branchLocationID> > >)); args.Add(filter.BranchLocationID); } if (filter.StartDate != null) { fsAppointmentList = fsAppointmentList.WhereAnd(typeof(Where <FSAppointment.scheduledDateTimeBegin, GreaterEqual <Required <FSAppointment.scheduledDateTimeBegin> > >)); args.Add(filter.StartDateWithTime); } if (filter.EndDateWithTime != null) { fsAppointmentList = fsAppointmentList.WhereAnd(typeof(Where <FSAppointment.scheduledDateTimeEnd, LessEqual <Required <FSAppointment.scheduledDateTimeEnd> > >)); args.Add(filter.EndDateWithTime); } if (staffSelected != null && staffSelected.Count() > 0) { fsAppointmentList = fsAppointmentList.WhereAnd(typeof(Where <FSAppointment.primaryDriver, In <Required <FSAppointment.primaryDriver> > >)); int[] staffResult = StaffMemberFilter.Select() .RowCast <FSAppointmentStaffMember>() .Where(_ => _.Selected == true) .Select(_ => _.BAccountID) .Cast <int>() .ToArray(); args.Add(staffResult); } PXView appointmentView = new PXView(graph, true, fsAppointmentList); var fsAppointmentSet = appointmentView.SelectMulti(args.ToArray()); foreach (PXResult <FSAppointment, FSServiceOrder, FSAddress> row in fsAppointmentSet) { FSAppointment fsAppointmentRow = (FSAppointment)row; fsAddressRow = (FSAddress)row; address = SharedFunctions.GetAddressForGeolocation( fsAddressRow.PostalCode, fsAddressRow.AddressLine1, fsAddressRow.AddressLine2, fsAddressRow.City, fsAddressRow.State, fsAddressRow.CountryID); Waypoint wp = GetWaypointFromAppointment(fsSetupRow, fsAppointmentRow, address); if (wp != null) { requestBody.waypoints.Add(wp); processList.Add(fsAppointmentRow); } else { UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.ADDRESS_ERROR); graph.Appointments.Update(fsAppointmentRow); } } } //Appointment Logic for (int i = list.Count - 1; i >= 0; i--) { bool addressError = false; try { address = SharedFunctions.GetAddressForGeolocation( list[i].PostalCode, list[i].AddressLine1, list[i].AddressLine2, list[i].City, list[i].State, list[i].CountryID); Waypoint wp = GetWaypointFromAppointment(fsSetupRow, list[i], address); if (wp != null) { requestBody.waypoints.Add(wp); processList.Add(list[i]); } else { addressError = true; } } catch { addressError = true; } if (addressError == true) { addressError = false; FSAppointment fsAppointmentRow = list[i]; UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.ADDRESS_ERROR); graph.Appointments.Update(fsAppointmentRow); list.RemoveAt(i); PXProcessing <FSAppointmentFSServiceOrder> .SetError(i, PXMessages.LocalizeFormatNoPrefix(TX.Error.MAPS_FAILED_REVERSE_ADRESS, TX.TableName.APPOINTMENT)); } } if (graph.Appointments.Cache.IsDirty == true) { graph.Appointments.Cache.Persist(PXDBOperation.Update); } try { SingleDayOptimizationOutput responseObject = client.getSingleDayOptimization(fsSetupRow.ROWWApiEndPoint, fsSetupRow.ROWWLicensekey, requestBody); AppointmentEntry graphAppointmentEntry = PXGraph.CreateInstance <AppointmentEntry>(); for (int i = 0; i < responseObject.routes.Count; i++) { int assignedstaffID; int.TryParse(responseObject.routes[i].vehicle.name, out assignedstaffID); bool changeFlag = false; for (int j = 1; j < responseObject.routes[i].steps.Count - 1; j++) { RouteOtimizer.RouteStep currentAppointment = responseObject.routes[i].steps[j]; int appointmentID; int.TryParse(currentAppointment.waypoint.name, out appointmentID); FSAppointment fsAppointmentListRow = processList.Find(x => x.AppointmentID == appointmentID); var newBegin = convertSecToTime(currentAppointment.serviceStartTimeSec, fsAppointmentListRow.ScheduledDateTimeBegin); var newEnd = newBegin.AddSeconds(currentAppointment.departureTimeSec - currentAppointment.arrivalTimeSec); UpdateAppointmentHeader(fsAppointmentListRow, ID.Status_ROOptimization.OPTIMIZED, j, null, newBegin, newEnd); if (fsAppointmentListRow.PrimaryDriver != null) { graph.Appointments.Update(fsAppointmentListRow); changeFlag = true; } else { fsAppointmentListRow.PrimaryDriver = assignedstaffID; FSAppointment fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current = graphAppointmentEntry.AppointmentRecords.Search <FSAppointment.refNbr>( fsAppointmentListRow.RefNbr, fsAppointmentListRow.SrvOrdType); UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.OPTIMIZED, j, assignedstaffID, newBegin, newEnd); graphAppointmentEntry.AppointmentRecords.Update(fsAppointmentRow); FSAppointmentEmployee fsAppointmentEmployeeRow_New = new FSAppointmentEmployee() { AppointmentID = fsAppointmentRow.AppointmentID, EmployeeID = assignedstaffID }; fsAppointmentEmployeeRow_New = graphAppointmentEntry.AppointmentServiceEmployees.Insert(fsAppointmentEmployeeRow_New); graphAppointmentEntry.Save.Press(); } } if (changeFlag == true) { graph.Appointments.Cache.Persist(PXDBOperation.Update); } } foreach (OutputWaypoint wp in responseObject.unreachableWaypoints.Concat(responseObject.unreachedWaypoints).GroupBy(p => p.name).Select(g => g.First()).ToList()) { int appointmentID; int.TryParse(wp.name, out appointmentID); FSAppointment fsAppointmentRow = list.Find(x => x.AppointmentID == appointmentID); if (fsAppointmentRow != null) { for (int i = 0; i < list.Count; i++) { if (fsAppointmentRow.AppointmentID == list[i].AppointmentID) { UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.NOT_ABLE); graph.Appointments.Update(fsAppointmentRow); PXProcessing <FSAppointmentFSServiceOrder> .SetError(i, PXMessages.LocalizeFormatNoPrefix(TX.Error.APPOINTMENT_COULD_NOT_BE_REACH_SERVICED)); } } } } graph.Appointments.Cache.Persist(PXDBOperation.Update); } catch (PXException e) { for (int i = 0; i < list.Count; i++) { FSAppointment fsAppointmentRow = list[i]; UpdateAppointmentHeader(fsAppointmentRow, ID.Status_ROOptimization.NOT_ABLE); graph.Appointments.Update(fsAppointmentRow); PXProcessing <FSAppointmentFSServiceOrder> .SetError(i, PXMessages.LocalizeFormatNoPrefix(e.Message)); } graph.Appointments.Cache.Persist(PXDBOperation.Update); } }
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(); }