public virtual void CloneServices(AppointmentEntry gOriginalAppt, AppointmentEntry gNewAppt, FSAppointment newAppointmentRow, FSAppointmentDet sourceRow, Dictionary <string, string> itemLineRef) { if (sourceRow == null || sourceRow.Status == ID.Status_AppointmentDet.CANCELED) { return; } // Creates a copy to not edit the original row. FSAppointmentDet sourceRowCopy = PXCache <FSAppointmentDet> .CreateCopy(sourceRow); ClearSourceLineBeforeCopy(sourceRowCopy); FSAppointmentDet newRow = new FSAppointmentDet(); newRow = AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSAppointmentDet>( gNewAppt.AppointmentDetails.Cache, newRow, gOriginalAppt.AppointmentDetails.Cache, sourceRowCopy, null, sourceRowCopy.SODetID, copyTranDate: false, tranDate: sourceRowCopy.TranDate, SetValuesAfterAssigningSODetID: true, copyingFromQuote: false); PXNoteAttribute.CopyNoteAndFiles( gOriginalAppt.AppointmentDetails.Cache, sourceRow, gNewAppt.AppointmentDetails.Cache, newRow, copyNotes: true, copyFiles: false); gNewAppt.AppointmentDetails.SetValueExt <FSAppointmentDet.acctID>(newRow, sourceRowCopy.AcctID); gNewAppt.AppointmentDetails.SetValueExt <FSAppointmentDet.subID>(newRow, sourceRowCopy.SubID); itemLineRef.Add(sourceRow.LineRef, newRow.LineRef); }
/// <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 CloneParts(AppointmentEntry gOriginalAppt, AppointmentEntry gNewAppt, FSAppointment newAppointmentRow, FSAppointmentDet sourceRow) { if (sourceRow == null || sourceRow.Status == ID.Status_AppointmentDet.CANCELED) { return; } FSSODet fsSODetRow = ServiceOrderCore.GetSODetFromAppointmentDet(gOriginalAppt, sourceRow); if (fsSODetRow == null) { return; } if (ReadingGraph == null) { ReadingGraph = new PXGraph(); } FSAppointmentDet takenQtyByAppointments = PXSelectJoinGroupBy <FSAppointmentDet, InnerJoin <FSAppointment, On < FSAppointment.srvOrdType, Equal <FSAppointmentDet.srvOrdType>, And <FSAppointment.refNbr, Equal <FSAppointmentDet.refNbr> > > >, Where < FSAppointmentDet.sODetID, Equal <Required <FSAppointmentDet.sODetID> >, And <FSAppointment.status, NotEqual <FSAppointment.status.Canceled>, And <FSAppointmentDet.isCanceledNotPerformed, NotEqual <True> > > >, Aggregate < GroupBy <FSAppointmentDet.sODetID, Sum <FSAppointmentDet.billableQty> > > > .Select(ReadingGraph, sourceRow.SODetID); decimal?openQty = fsSODetRow.BillableQty - (takenQtyByAppointments?.BillableQty ?? 0m); decimal?qtyFromBal = openQty >= sourceRow.BillableQty ? sourceRow.BillableQty : openQty > 0m ? openQty : 0m; decimal? missingQty = sourceRow.BillableQty - qtyFromBal; FSAppointmentDet noteLine = null; // Creates a copy to not edit the original row. FSAppointmentDet sourceRowCopy = PXCache <FSAppointmentDet> .CreateCopy(sourceRow); ClearSourceLineBeforeCopy(sourceRowCopy); if (qtyFromBal > 0) { sourceRowCopy.EstimatedQty = qtyFromBal; sourceRowCopy.BillableQty = qtyFromBal; FSAppointmentDet newRow = new FSAppointmentDet(); newRow = AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSAppointmentDet>( gNewAppt.AppointmentDetails.Cache, newRow, gOriginalAppt.AppointmentDetails.Cache, sourceRowCopy, null, sourceRowCopy.SODetID, copyTranDate: false, tranDate: sourceRowCopy.TranDate, SetValuesAfterAssigningSODetID: true, copyingFromQuote: false); noteLine = newRow; } if (missingQty > 0) { sourceRowCopy.EstimatedQty = missingQty; sourceRowCopy.BillableQty = missingQty; FSAppointmentDet newRow = new FSAppointmentDet(); newRow = AppointmentEntry.InsertDetailLine <FSAppointmentDet, FSAppointmentDet>( gNewAppt.AppointmentDetails.Cache, newRow, gOriginalAppt.AppointmentDetails.Cache, sourceRowCopy, null, null, copyTranDate: false, tranDate: sourceRowCopy.TranDate, SetValuesAfterAssigningSODetID: true, copyingFromQuote: false); if (noteLine == null) { noteLine = newRow; } } if (noteLine != null) { PXNoteAttribute.CopyNoteAndFiles(gOriginalAppt.AppointmentDetails.Cache, sourceRow, gNewAppt.AppointmentDetails.Cache, noteLine, copyNotes: true, copyFiles: false); } }