Exemple #1
0
        /// <summary>
        /// Enable/Disable the ActionType field for a Service depending on the appointments related to that service.
        /// </summary>
        private void EnableDisableActionType(PXCache cache, InventoryItem inventoryItemRow)
        {
            bool       enableActionType = true;
            FSxService fsxServiceRow    = PXCache <InventoryItem> .GetExtension <FSxService>(inventoryItemRow);

            if (cache.GetStatus(inventoryItemRow) != PXEntryStatus.Inserted)
            {
                int rowCount = PXSelect <FSAppointmentInventoryItem,
                                         Where <
                                             FSAppointmentInventoryItem.lineType, Equal <ListField_LineType_Pickup_Delivery.Pickup_Delivery>,
                                             And <FSAppointmentInventoryItem.pickupDeliveryServiceID, Equal <Required <FSAppointmentInventoryItem.pickupDeliveryServiceID> > > > >
                               .SelectSingleBound(cache.Graph, null, inventoryItemRow.InventoryID).Count;

                enableActionType = rowCount == 0;
            }

            PXUIFieldAttribute.SetEnabled <FSxService.actionType>(cache, inventoryItemRow, enableActionType);

            if (enableActionType == false)
            {
                cache.RaiseExceptionHandling <FSxService.actionType>(
                    inventoryItemRow,
                    null,
                    new PXSetPropertyException(
                        PXMessages.LocalizeFormat(TX.Warning.CANNOT_MODIFY_FIELD, "Appoinments", "Service"),
                        PXErrorLevel.Warning));
            }
        }
Exemple #2
0
            public override void SubstituteKeyFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
            {
                BAccountR baccount = null;

                if (e.NewValue != null)
                {
                    baccount = PXSelect <BAccountR,
                                         Where <BAccountR.acctCD, Equal <Required <BAccountR.acctCD> > > > .
                               SelectWindowed(sender.Graph, 0, 1, e.NewValue);

                    if (baccount != null)
                    {
                        e.NewValue = baccount.BAccountID;
                        e.Cancel   = true;
                    }
                    else if (e.NewValue.GetType() == typeof(Int32))
                    {
                        baccount = PXSelect <BAccountR,
                                             Where <BAccountR.bAccountID, Equal <Required <BAccountR.bAccountID> > > > .
                                   SelectWindowed(sender.Graph, 0, 1, e.NewValue);
                    }
                    if (baccount == null)
                    {
                        throw new PXSetPropertyException(PXMessages.LocalizeFormat(ErrorMessages.ValueDoesntExist, _FieldName, e.NewValue));
                    }
                }
            }
Exemple #3
0
                protected override string CreateEditPreventingReason(GetEditPreventingReasonArgs args,
                                                                     object firstPreventingEntity, string fieldName, string currentTableName, string foreignTableName)
                {
                    var planType = INPlanType.PK.Find(args.Graph, ((INItemPlan)firstPreventingEntity).PlanType);

                    return(PXMessages.LocalizeFormat(IN.Messages.DecimalBaseUnitCouldNotUnchecked, ((InventoryItem)args.Row).BaseUnit, planType.Descr));
                }
		public override void RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
		{
			object val;
			if (_PersistingCheck != PXPersistingCheck.Nothing &&
				((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert ||
				(e.Operation & PXDBOperation.Command) == PXDBOperation.Update) &&
				(val = sender.GetValue(e.Row, _FieldOrdinal)) != null && (decimal)val != 1m)
			{
				val = (decimal)val * 100m;
				if (_MapErrorTo == null)
				{
					if (sender.RaiseExceptionHandling(_FieldName, e.Row, val, new PXSetPropertyException(PXMessages.LocalizeFormat(Messages.WrongValue, _FieldName))))
					{
						throw new PXRowPersistingException(_FieldName, null, Messages.WrongValue, _FieldName);
					}
				}
				else
				{
					string name = _MapErrorTo.Name;
					name = char.ToUpper(name[0]) + name.Substring(1);
					val = sender.GetValueExt(e.Row, name);
					if (val is PXFieldState)
					{
						val = ((PXFieldState)val).Value;
					}
					if (sender.RaiseExceptionHandling(name, e.Row, val, new PXSetPropertyException(PXMessages.LocalizeFormat(Messages.WrongValue, name, _FieldName))))
					{
						throw new PXRowPersistingException(_FieldName, null, Messages.WrongValue, _FieldName);
					}
				}
			}
		}
Exemple #5
0
        /// <summary>
        /// Closes all appointments belonging to the current Route, in case an error occurs with any appointment,
        /// the route will not be closed and a message will be displayed alerting the user about the appointment's issue.
        /// The row of the appointment having problems is marked with its error.
        /// </summary>
        /// <param name="errorMessage">Error message to be displayed.</param>
        /// <returns>True in case all appointments are closed, otherwise False.</returns>
        private bool CloseAppointmentsInRoute(ref string errorMessage)
        {
            bool allAppointmentsClosed = true;

            PXResultset <FSAppointment> bqlResultSet = AppointmentsInRoute.Select();

            if (bqlResultSet.Count > 0)
            {
                Dictionary <FSAppointment, string> appWithErrors = SharedFunctions.CloseAppointments(bqlResultSet);

                if (appWithErrors.Count > 0)
                {
                    foreach (KeyValuePair <FSAppointment, string> kvp in appWithErrors)
                    {
                        AppointmentsInRoute.Cache.RaiseExceptionHandling <FSAppointment.refNbr>(
                            kvp.Key,
                            kvp.Key.RefNbr,
                            new PXSetPropertyException(kvp.Value, PXErrorLevel.RowError));
                    }

                    allAppointmentsClosed = false;
                    errorMessage          = PXMessages.LocalizeFormat(TX.Error.ROUTE_CANT_BE_CLOSED_APPOINTMENTS_IN_ROUTE_HAVE_ISSUES);
                }
            }

            return(allAppointmentsClosed);
        }
        protected string PickAddressError <TFieldSource>(IAddressBase address)
            where TFieldSource : IBqlField
        {
            if (typeof(TFieldSource) == typeof(SOOrder.shipAddressID))
            {
                return(PXSelect <SOOrder, Where <SOOrder.shipAddressID, Equal <Required <Address.addressID> > > >
                       .SelectWindowed(Base, 0, 1, ((SOAddress)address).AddressID).First().GetItem <SOOrder>()
                       .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <SOOrder>(), new EntityHelper(Base).GetRowID(e))));
            }

            if (typeof(TFieldSource) == typeof(Vendor.defLocationID))
            {
                return(PXSelectReadonly2 <Vendor, InnerJoin <Location, On <Location.locationID, Equal <Vendor.defLocationID> > >, Where <Location.defAddressID, Equal <Required <Address.addressID> > > >
                       .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <Vendor>()
                       .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <Vendor>(), new EntityHelper(Base).GetRowID(e))));
            }

            if (typeof(TFieldSource) == typeof(INSite.addressID))
            {
                return(PXSelectReadonly <INSite, Where <INSite.addressID, Equal <Required <Address.addressID> > > >
                       .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <INSite>()
                       .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <INSite>(), new EntityHelper(Base).GetRowID(e))));
            }

            if (typeof(TFieldSource) == typeof(BAccountR.defAddressID))
            {
                return(PXSelectReadonly <BAccountR, Where <BAccountR.defAddressID, Equal <Required <Address.addressID> > > >
                       .SelectWindowed(Base, 0, 1, ((Address)address).AddressID).First().GetItem <BAccountR>()
                       .With(e => PXMessages.LocalizeFormat(AR.Messages.AvalaraAddressSourceError, EntityHelper.GetFriendlyEntityName <BAccountR>(), new EntityHelper(Base).GetRowID(e))));
            }

            throw new ArgumentOutOfRangeException("Unknown address source used");
        }
        /// <summary>
        /// Validates the CalendarWeekCodeGeneration.startDate value.
        /// </summary>
        /// <param name="calendarWeekCodeGenrationRow">CalendarWeekCodeGeneration Row.</param>
        /// <param name="cache">Cache of the View.</param>
        /// <returns>true: valid value | false: invalid value.</returns>
        private bool ValidateStartGenerationDate(CalendarWeekCodeGeneration calendarWeekCodeGenrationRow, PXCache cache)
        {
            bool isValid = true;

            if (calendarWeekCodeGenrationRow.StartDate == null)
            {
                cache.RaiseExceptionHandling <CalendarWeekCodeGeneration.startDate>(
                    calendarWeekCodeGenrationRow,
                    calendarWeekCodeGenrationRow.StartDate,
                    new PXException(PXMessages.LocalizeFormat(
                                        TX.Error.FIELD_MAY_NOT_BE_EMPTY,
                                        PXUIFieldAttribute.GetDisplayName <CalendarWeekCodeGeneration.endDate>(cache))));

                isValid = false;
            }
            else
            {
                if (calendarWeekCodeGenrationRow.StartDate < calendarWeekCodeGenrationRow.DefaultStartDate)
                {
                    cache.RaiseExceptionHandling <CalendarWeekCodeGeneration.startDate>(
                        calendarWeekCodeGenrationRow,
                        calendarWeekCodeGenrationRow.StartDate,
                        new PXException(TX.Error.START_DATE_LESSER_THAN_DEFAULT_DATE));
                    isValid = false;
                }
            }

            return(isValid);
        }
Exemple #8
0
            public override void SubstituteKeyFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
            {
                //base.SubstituteKeyFieldUpdating(sender, e);

                InventoryItem inventoryItem = null;

                if (e.NewValue != null)
                {
                    inventoryItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .SelectWindowed(sender.Graph, 0, 1, e.NewValue);

                    if (inventoryItem == null)
                    {
                        inventoryItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .SelectWindowed(sender.Graph, 0, 1, e.NewValue);
                    }
                }
                if (inventoryItem != null)
                {
                    e.NewValue = inventoryItem.InventoryID;
                    e.Cancel   = true;
                }
                else if (e.NewValue != null)
                {
                    throw new PXSetPropertyException(PXMessages.LocalizeFormat(ErrorMessages.ValueDoesntExist, _FieldName, e.NewValue));
                }
            }
        /// <summary>
        /// Returns the contact names or cell phones separated by a coma.
        /// </summary>
        /// <param name="bqlResultSet">Set of customer contacts.</param>
        /// <param name="concatenateNames">Boolean that if true, returns the customer contact's name(s).</param>
        /// <param name="concatenateCells">Boolean that if true, returns the customer contact's cell phone(s).</param>
        private static StringBuilder ConcatenatesContactInfo(PXResultset <Contact> bqlResultSet, bool concatenateNames, bool concatenateCells)
        {
            StringBuilder names = new StringBuilder();
            int           i     = 0;

            if (bqlResultSet.Count > 0)
            {
                foreach (Contact contactRow in bqlResultSet)
                {
                    i++;

                    if (bqlResultSet.Count > 1 && i == bqlResultSet.Count)
                    {
                        names.Append(PXMessages.LocalizeFormat(TX.Messages.LIST_LAST_ITEM_PREFIX));
                    }
                    else
                    {
                        if (names.Length != 0)
                        {
                            names.Append(", ");
                        }
                    }

                    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());
                    }

                    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_CUSTOMER);
                    }
                }
            }
            else if (concatenateNames == true)
            {
                names.Append(TX.Messages.NO_CONTACT_FOR_THE_CUSTOMER);
            }
            else if (concatenateCells == true)
            {
                names.Append(TX.Messages.NO_CONTACT_CELL_FOR_THE_CUSTOMER);
            }

            return(names);
        }
Exemple #10
0
        public Customer GetByCD(string accountCD)
        {
            var customer = FindByCD(accountCD);

            if (customer == null)
            {
                throw new PXSetPropertyException(PXMessages.LocalizeFormat(ErrorMessages.ValueDoesntExist,
                                                                           Messages.Customer, accountCD));
            }

            return(customer);
        }
        public static void RaiseRowPersistingException <Field>(PXCache cache, object row)
            where Field : IBqlField
        {
            var fieldName = typeof(Field).Name;

            cache.RaiseExceptionHandling <Field>(
                row,
                null,
                new PXSetPropertyException(PXMessages.LocalizeFormat(ErrorMessages.FieldIsEmpty, fieldName)));

            throw new PXRowPersistingException(fieldName, null, ErrorMessages.FieldIsEmpty, PXUIFieldAttribute.GetDisplayName <Field>(cache));
        }
        public string PXMessagesFormat()
        {
            string localizedString;
            object parameter = new object();

            localizedString = PXMessages.LocalizeFormat(InnerNamespace.NonLocalizableMessagesInNamespace.StringToFormat, parameter);
            localizedString = PXMessages.LocalizeFormat(NonLocalizableMessages.StringToFormat, out string prefix, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(NonLocalizableMessages.StringToFormat, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefixNLA(NonLocalizableMessages.StringToFormat, parameter);

            return(localizedString);
        }
        public string All()
        {
            string localizedString;
            object parameter = new object();

            localizedString = PXLocalizer.LocalizeFormat(MyMessages.CommasInUserName, parameter);
            localizedString = PXMessages.LocalizeFormat(MyMessages.CommasInUserName, parameter);
            localizedString = PXMessages.LocalizeFormat(MyMessages.CommasInUserName, out string refix, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(MyMessages.CommasInUserName, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefixNLA(MyMessages.CommasInUserName, parameter);

            return(localizedString);
        }
        public string PXMessagesLocalizationFormatMethods()
        {
            string localizedString;
            object parameter = new object();

            localizedString = PXMessages.LocalizeFormat(MyMessages.StringToFormat, parameter);
            localizedString = PXMessages.LocalizeFormat(MyMessages.StringToFormat, out string prefix, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(MyMessages.StringToFormat, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefixNLA(MyMessages.StringToFormat, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(ComplexMessages.DocDiscountExceedLimit, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(ComplexMessages.DateTimeStr, DateTime.Now);

            return(localizedString);
        }
        public virtual IEnumerable GenerateWeekCode(PXAdapter adapter)
        {
            if (CalendarWeekCodeGenerationOptions.AskExt() == WebDialogResult.OK)
            {
                if (ValidateEndGenerationDate(CalendarWeekCodeGenerationOptions.Current, CalendarWeekCodeGenerationOptions.Cache) &&
                    ValidateStartGenerationDate(CalendarWeekCodeGenerationOptions.Current, CalendarWeekCodeGenerationOptions.Cache))
                {
                    string message = PXMessages.LocalizeFormat(
                        TX.Messages.ASK_CONFIRM_CALENDAR_WEEKCODE_GENERATION,
                        CalendarWeekCodeGenerationOptions.Current.StartDate.Value.ToShortDateString(),
                        CalendarWeekCodeGenerationOptions.Current.EndDate.Value.ToShortDateString());

                    if (WebDialogResult.OK == CalendarWeekCodeRecords.Ask(
                            TX.WebDialogTitles.CONFIRM_CALENDAR_WEEKCODE_GENERATION,
                            message,
                            MessageButtons.OKCancel))
                    {
                        DateTime baseDate     = CalendarWeekCodeGenerationOptions.Current.DefaultStartDate.Value;
                        DateTime iteratorDate = CalendarWeekCodeGenerationOptions.Current.StartDate.Value;
                        DateTime stopDate     = CalendarWeekCodeGenerationOptions.Current.EndDate.Value;

                        CalendarWeekCodeMaint graphCalendarWeekCodeMaint = PXGraph.CreateInstance <CalendarWeekCodeMaint>();

                        PXLongOperation.StartOperation(
                            this,
                            delegate
                        {
                            while (iteratorDate <= stopDate)
                            {
                                FSWeekCodeDate fsWeekCodeRow = new FSWeekCodeDate();
                                fsWeekCodeRow.WeekCodeDate   = iteratorDate;

                                graphCalendarWeekCodeMaint.AutoCalcWeekCode(baseDate, fsWeekCodeRow);

                                graphCalendarWeekCodeMaint.CalendarWeekCodeRecords.Insert(fsWeekCodeRow);
                                iteratorDate = iteratorDate.AddDays(1);
                            }

                            graphCalendarWeekCodeMaint.Save.Press();
                        });
                    }
                }
                else
                {
                    throw new PXException(TX.Error.INVALID_WEEKCODE_GENERATION_OPTIONS);
                }
            }

            return(adapter.Get());
        }
Exemple #16
0
        public Func <decimal?, decimal> GetRoundDelegateForLedger(int?ledgerID)
        {
            var currency = (Currency)PXSelectJoin <Currency,
                                                   InnerJoin <Ledger,
                                                              On <Currency.curyID, Equal <Ledger.baseCuryID> > >,
                                                   Where
                                                   <Ledger.ledgerID, Equal <Required <Ledger.ledgerID> > > >
                           .Select(this, ledgerID);

            if (currency == null)
            {
                throw new PXException(
                          PXMessages.LocalizeFormat(Messages.CurrencyForLedgerCannotBeFound, ledgerID));
            }

            return(value => Math.Round(value.Value, currency.DecimalPlaces.Value, MidpointRounding.AwayFromZero));
        }
Exemple #17
0
        protected virtual void FSSetup_AppAutoConfirmGap_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSSetup fsSetupRow = (FSSetup)e.Row;

            if (fsSetupRow.AppAutoConfirmGap < 1)
            {
                cache.RaiseExceptionHandling <FSSetup.appAutoConfirmGap>(
                    fsSetupRow,
                    fsSetupRow.AppAutoConfirmGap,
                    new PXSetPropertyException(PXMessages.LocalizeFormat(TX.Error.MINIMUN_VALUE, " 00 h 01 m"), PXErrorLevel.Error));
            }
        }
        protected virtual void FSRouteEmployee_PriorityPreference_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSRouteEmployee fsRouteEmployeeRow = (FSRouteEmployee)e.Row;

            if (fsRouteEmployeeRow.PriorityPreference < 1)
            {
                cache.RaiseExceptionHandling <FSRouteEmployee.priorityPreference>(
                    fsRouteEmployeeRow,
                    fsRouteEmployeeRow.PriorityPreference,
                    new PXSetPropertyException(PXMessages.LocalizeFormat(TX.Error.MINIMUN_VALUE, 1), PXErrorLevel.Error));
            }
        }
        protected virtual void FSRouteEmployee_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            FSRouteEmployee fsRouteEmployeeRow = (FSRouteEmployee)e.Row;

            if (fsRouteEmployeeRow.PriorityPreference < 1)
            {
                cache.RaiseExceptionHandling <FSRouteEmployee.priorityPreference>(
                    fsRouteEmployeeRow,
                    fsRouteEmployeeRow.PriorityPreference,
                    new PXSetPropertyException(PXMessages.LocalizeFormat(TX.Error.MINIMUN_VALUE, 1), PXErrorLevel.Error));

                throw new PXException(PXMessages.LocalizeFormat(TX.Error.MINIMUN_VALUE_NAME_FIELD, "Priority Option", 1), PXErrorLevel.Error);
            }
        }
Exemple #20
0
        public string All()
        {
            string localizedString;
            object parameter = new object();

            localizedString = PXLocalizer.Localize(MyMessages.CommasInUserName + MyMessages.SomeString);
            localizedString = PXLocalizer.Localize(string.Format(MyMessages.StringToFormat, parameter), typeof(MyMessages).FullName);
            localizedString = PXLocalizer.LocalizeFormat(String.Concat(MyMessages.CommasInUserName, MyMessages.SomeString), parameter);

            localizedString = PXMessages.Localize(MyMessages.CommasInUserName + "123");
            localizedString = PXMessages.Localize(string.Format(MyMessages.StringToFormat, 123), out string strPrefix);
            localizedString = PXMessages.LocalizeNoPrefix(string.Concat(MyMessages.CommasInUserName, "123"));

            localizedString = PXMessages.LocalizeFormat(MyMessages.StringToFormat + "456", parameter);
            localizedString = PXMessages.LocalizeFormat(string.Format(MyMessages.StringToFormat, parameter), out string prefix, parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefix(string.Concat(MyMessages.StringToFormat, "456"), parameter);
            localizedString = PXMessages.LocalizeFormatNoPrefixNLA(string.Concat(MyMessages.StringToFormat, "456", "789"), parameter);

            return(localizedString);
        }
        /// <summary>
        /// Enables/Disables the Item Type field depending of there is at least one service related to.
        /// </summary>
        /// <param name="cache">PXCache instance.</param>
        /// <param name="itemClassRow">The current INItemClass object row.</param>
        /// <param name="fsxServiceClassRow">The current <c>FSxServiceClass</c> object row.</param>
        private void EnableDisable_ItemType(PXCache cache, INItemClass itemClassRow, FSxServiceClass fsxServiceClassRow)
        {
            bool enableItemType = true;
            PXSetPropertyException exception = null;

            if (itemClassRow.ItemType == INItemTypes.ServiceItem && cache.GetStatus(itemClassRow) != PXEntryStatus.Inserted)
            {
                int rowCount = PXSelectJoin <InventoryItem,
                                             InnerJoin <INItemClass,
                                                        On <INItemClass.itemClassID, Equal <InventoryItem.itemClassID> > >,
                                             Where <
                                                 InventoryItem.itemClassID, Equal <Required <InventoryItem.itemClassID> >,
                                                 And <InventoryItem.itemType, Equal <INItemTypes.serviceItem> > > >
                               .SelectWindowed(cache.Graph, 0, 1, itemClassRow.ItemClassID).Count;

                enableItemType = rowCount == 0;
            }

            if (enableItemType == false)
            {
                exception = new PXSetPropertyException(
                    PXMessages.LocalizeFormat(TX.Warning.CANNOT_MODIFY_FIELD, "Services", "Item Class"),
                    PXErrorLevel.Warning);
            }

            cache.RaiseExceptionHandling <INItemClass.itemType>(
                itemClassRow,
                itemClassRow.ItemType,
                exception
                );

            cache.RaiseExceptionHandling <FSxServiceClass.requireRoute>(
                itemClassRow,
                fsxServiceClassRow.RequireRoute,
                exception
                );

            PXUIFieldAttribute.SetEnabled <INItemClass.itemType>(cache, itemClassRow, enableItemType);
            PXUIFieldAttribute.SetEnabled <FSxServiceClass.requireRoute>(cache, itemClassRow, enableItemType);
        }
        public virtual ProcessingResult <FABookPeriod> FindMappedFABookPeriodUsingFinPeriod(int?bookID, int?sourceOrganizationID, string sourcefinPeriodID, int?targetOrganizationID)
        {
            IFinPeriodRepository finPeriodRepository = Graph.GetService <IFinPeriodRepository>();

            string       targetFinPeriodID  = finPeriodRepository.GetMappedPeriod(sourceOrganizationID, sourcefinPeriodID, targetOrganizationID)?.FinPeriodID;
            FABookPeriod targetFABookPeriod = FindByKey(bookID, targetOrganizationID, targetFinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(targetFABookPeriod);

            if (targetFABookPeriod == null)
            {
                string errorMessage = PXMessages.LocalizeFormat(
                    Messages.PeriodDoesNotExistForBookAndCompany,
                    PeriodIDAttribute.FormatForError(sourcefinPeriodID),
                    FindFABook(bookID).BookCode,
                    PXAccess.GetOrganizationCD(sourceOrganizationID));

                result.AddErrorMessage(errorMessage);
            }

            return(result);
        }
        protected virtual void VerifyIsAlreadyPosted <Field>(PXCache cache, FSAppointmentDet fsAppointmentDetRow, FSAppointmentInventoryItem fsAppointmentInventoryItemRow, FSBillingCycle billingCycleRow)
            where Field : class, IBqlField
        {
            if ((fsAppointmentDetRow == null && fsAppointmentInventoryItemRow == null) || ServiceOrderRelated.Current == null || billingCycleRow == null)
            {
                return;
            }

            IFSSODetBase row   = null;
            int?         pivot = -1;

            if (fsAppointmentDetRow != null)
            {
                row   = fsAppointmentDetRow;
                pivot = fsAppointmentDetRow.SODetID;
            }
            else if (fsAppointmentInventoryItemRow != null)
            {
                row   = fsAppointmentInventoryItemRow;
                pivot = fsAppointmentInventoryItemRow.AppDetID > 0 ? fsAppointmentInventoryItemRow.AppDetID : null;
            }

            PXEntryStatus status            = ServiceOrderRelated.Cache.GetStatus(ServiceOrderRelated.Current);
            bool          needsVerify       = status == PXEntryStatus.Updated || status == PXEntryStatus.Notchanged;
            bool          isSOAlreadyPosted = ServiceOrderPostedIn.Select().Count > 0;

            if (needsVerify == true &&
                pivot == null &&
                IsInstructionOrComment(row) == false &&
                billingCycleRow.BillingBy == ID.Billing_By.SERVICE_ORDER &&
                isSOAlreadyPosted == true)
            {
                cache.RaiseExceptionHandling <Field>(row,
                                                     row.InventoryID,
                                                     new PXSetPropertyException(
                                                         PXMessages.LocalizeFormat(TX.Error.CANNOT_ADD_INVENTORY_TYPE_LINES_BECAUSE_SO_POSTED, GetLineType(row.LineType)),
                                                         PXErrorLevel.RowError));
            }
        }
        public virtual ProcessingResult <FABookPeriod> FindMappedFABookPeriod(int?bookID, int?sourceOrganizationID, string sourcefinPeriodID, int?targetOrganizationID)
        {
            FABookPeriod sourceFABookPeriod = FindByKey(bookID, sourceOrganizationID, sourcefinPeriodID);

            ProcessingResult <FABookPeriod> result = ProcessingResult <FABookPeriod> .CreateSuccess(sourceFABookPeriod);

            if (sourceFABookPeriod == null)
            {
                string errorMessage = PXMessages.LocalizeFormat(
                    Messages.PeriodDoesNotExistForBookAndCompany,
                    PeriodIDAttribute.FormatForError(sourcefinPeriodID),
                    FindFABook(bookID).BookCode,
                    PXAccess.GetOrganizationCD(sourceOrganizationID));

                result.AddErrorMessage(errorMessage);
            }
            else if (IsPostingFABook(bookID) && sourceOrganizationID != targetOrganizationID)
            {
                result = GetFABookPeriodByMasterPeriodID(bookID, targetOrganizationID, sourceFABookPeriod?.MasterFinPeriodID);
            }

            return(result);
        }
Exemple #25
0
        public override void SubstituteKeyFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
        {
            PMCostCode costCode = null;

            if (e.NewValue != null)
            {
                costCode = PXSelect <PMCostCode, Where <PMCostCode.costCodeCD, Equal <Required <PMCostCode.costCodeCD> > > > .SelectWindowed(sender.Graph, 0, 1, e.NewValue);

                if (costCode != null)
                {
                    e.NewValue = costCode.CostCodeID;
                    e.Cancel   = true;
                }
                else if (e.NewValue.GetType() == typeof(int))
                {
                    costCode = PXSelect <PMCostCode, Where <PMCostCode.costCodeID, Equal <Required <PMCostCode.costCodeID> > > > .SelectWindowed(sender.Graph, 0, 1, e.NewValue);
                }
                if (costCode == null)
                {
                    throw new PXSetPropertyException(PXMessages.LocalizeFormat(ErrorMessages.ValueDoesntExist, _FieldName, e.NewValue));
                }
            }
        }
        /// <summary>
        /// Generates Appointments (Routes Contract) or Service Orders (Service Contract) for each TimeSlot in the [scheduleRules] List.
        /// </summary>
        public void GenerateAPPSOUpdateContracts(List <Schedule> scheduleRules, string recordType, DateTime?fromDate, DateTime?toDate, FSSchedule fsScheduleRow)
        {
            var      generator      = new TimeSlotGenerator();
            DateTime processEndDate = (DateTime)GetProcessEndDate(scheduleRules.ElementAt(0), toDate);

            var period = new Period((DateTime)fromDate, processEndDate);

            // Determines the next generationID number
            if (nextGenerationID == null)
            {
                FSProcessIdentity fsProcessIdentityRow = new FSProcessIdentity();
                fsProcessIdentityRow.ProcessType  = recordType;
                fsProcessIdentityRow.FilterFromTo = fromDate;
                fsProcessIdentityRow.FilterUpTo   = toDate;

                ProcessIdentityMaint graphProcessIdentityMaint = PXGraph.CreateInstance <ProcessIdentityMaint>();
                graphProcessIdentityMaint.processIdentityRecords.Insert(fsProcessIdentityRow);
                graphProcessIdentityMaint.Save.Press();

                nextGenerationID = graphProcessIdentityMaint.processIdentityRecords.Current.ProcessID;
            }

            List <TimeSlot> timeSlots   = generator.GenerateCalendar(period, scheduleRules, nextGenerationID);
            DateTime?       failsOnDate = null;

            // Transaction to create the appointments (Routes Contract) or Service Orders (Service Contract)
            using (PXTransactionScope ts = new PXTransactionScope())
            {
                Customer customerRow = PXSelect <Customer,
                                                 Where <
                                                     Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >
                                       .Select(this, fsScheduleRow.CustomerID)
                                       .FirstOrDefault();

                if (customerRow.Status != BAccount.status.Active && customerRow.Status != BAccount.status.OneTime)
                {
                    throw new PXException(PXMessages.LocalizeFormat(AR.Messages.CustomerIsInStatus, new Customer.status.ListAttribute().ValueLabelDic[customerRow.Status]));
                }

                try
                {
                    foreach (var timeSlot in timeSlots)
                    {
                        failsOnDate = timeSlot.DateTimeBegin;

                        if (recordType == ID.RecordType_ServiceContract.SERVICE_CONTRACT)
                        {
                            bool createAppointmnet = fsScheduleRow.ScheduleGenType == ID.ScheduleGenType_ServiceContract.APPOINTMENT;

                            CreateServiceOrder(timeSlot, createAppointmnet);
                        }
                        else if (recordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT)
                        {
                            CreateServiceOrder(timeSlot, true, true);
                        }
                    }

                    DateTime?lastGenerationDate = null;

                    if (timeSlots.Count > 0)
                    {
                        lastGenerationDate = timeSlots.Max(a => a.DateTimeBegin);
                    }

                    CreateContractGenerationHistory((int)nextGenerationID,
                                                    scheduleRules.ElementAt(0).ScheduleID,
                                                    processEndDate,
                                                    lastGenerationDate,
                                                    recordType);

                    UpdateGeneratedSchedule(scheduleRules.ElementAt(0).ScheduleID, processEndDate, lastGenerationDate, fsScheduleRow);
                }
                catch (Exception e)
                {
                    var exceptionWithContextMessage = ExceptionHelper.GetExceptionWithContextMessage(PXMessages.Localize(TX.Messages.COULD_NOT_PROCESS_RECORD), e);

                    FSGenerationLogError fsGenerationLogErrorRow = new FSGenerationLogError();
                    fsGenerationLogErrorRow.ProcessType  = recordType;
                    fsGenerationLogErrorRow.ErrorMessage = exceptionWithContextMessage.Message;
                    fsGenerationLogErrorRow.ScheduleID   = scheduleRules.ElementAt(0).ScheduleID;
                    fsGenerationLogErrorRow.GenerationID = nextGenerationID;
                    fsGenerationLogErrorRow.ErrorDate    = failsOnDate;

                    ts.Dispose();

                    var grapGenerationLogErrorMaint = PXGraph.CreateInstance <GenerationLogErrorMaint>();

                    grapGenerationLogErrorMaint.LogErrorMessageRecords.Insert(fsGenerationLogErrorRow);
                    grapGenerationLogErrorMaint.Save.Press();
                    throw exceptionWithContextMessage;
                }

                ts.Complete(this);
            }
        }