private int IsListAttributeField(PXCache cache, Type field)
        {
            int result;

            if (isListAttributeTable.TryGetValue(field, out result))
            {
                return(result);
            }
            else
            {
                var list            = cache.GetAttributes(field.Name);
                int isListAttribute = 0;

                foreach (var attr in list)
                {
                    if (attr is PXStringListAttribute)
                    {
                        isListAttribute = ((PXStringListAttribute)attr).IsLocalizable ? 2 : 1;
                        break;
                    }
                    else if (attr is PXIntListAttribute)
                    {
                        isListAttribute = ((PXIntListAttribute)attr).IsLocalizable ? 2 : 1;
                        break;
                    }
                }

                isListAttributeTable.Add(field, isListAttribute);
                return(isListAttribute);
            }
        }
Пример #2
0
 public virtual void CCTransactionsHistoryFilter_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
 {
     if (e.Row != null)
     {
         PXCache.TryDispose(sender.GetAttributes <CCTransactionsHistoryFilter.cardNumber>(e.Row));
     }
 }
 public static void Activate(PXCache cache)
 {
     foreach (PXDBAttributeAttribute attribute in cache.GetAttributes(null).OfType <PXDBAttributeAttribute>())
     {
         attribute._IsActive = true;
     }
 }
Пример #4
0
        private bool IsListAttributeField(PXCache cache, Type field)
        {
            bool result;

            if (isListAttributeTable.TryGetValue(field, out result))
            {
                return(result);
            }
            else
            {
                var  list            = cache.GetAttributes(field.Name);
                bool isListAttribute = false;

                foreach (var attr in list)
                {
                    if (attr is PXStringListAttribute || attr is PXIntListAttribute)
                    {
                        isListAttribute = true;
                        break;
                    }
                }

                isListAttributeTable.Add(field, isListAttribute);
                return(isListAttribute);
            }
        }
Пример #5
0
        public static void NewChild(PXCache cache, object parentrow, Type ParentType, out object child)
        {
            foreach (PXEventSubscriberAttribute attr in cache.GetAttributes(null))
            {
                if (attr is PXParentAttribute && ((PXParentAttribute)attr).ParentType.IsAssignableFrom(ParentType))
                {
                    Type childType = cache.GetItemType();

                    PXView parentView = ((PXParentAttribute)attr).GetParentSelect(cache);
                    Type   parentType = parentView.BqlSelect.GetFirstTable();

                    PXView     childView   = ((PXParentAttribute)attr).GetChildrenSelect(cache);
                    BqlCommand selectChild = childView.BqlSelect;

                    IBqlParameter[] pars = selectChild.GetParameters();
                    Type[]          refs = selectChild.GetReferencedFields(false);

                    child = Activator.CreateInstance(childType);
                    PXCache parentcache = cache.Graph.Caches[parentType];

                    for (int i = 0; i < Math.Min(pars.Length, refs.Length); i++)
                    {
                        Type   partype = pars[i].GetReferencedType();
                        object val     = parentcache.GetValue(parentrow, partype.Name);

                        cache.SetValue(child, refs[i].Name, val);
                    }
                    return;
                }
            }
            child = null;
        }
Пример #6
0
        public static bool HasError <TField>(this PXCache cache, object row, string errorMessage)
            where TField : IBqlField
        {
            var fieldName = cache.GetField(typeof(TField));

            return(cache.GetAttributes(row, fieldName).OfType <IPXInterfaceField>()
                   .Any(field => field.ErrorText == errorMessage));
        }
Пример #7
0
 public static void SetPrefix <Field>(PXCache sender, object row, string prefix) where Field : IBqlField
 {
     foreach (PXEventSubscriberAttribute attribute in sender.GetAttributes <Field>(row))
     {
         if (attribute is AutoNumberAttribute)
         {
             ((AutoNumberAttribute)attribute).Prefix = prefix;
         }
     }
 }
 public static void UpdateStatus(PXCache cache, CAAdj row)
 {
     foreach (var attr in cache.GetAttributes <CAAdj.status>(row))
     {
         if (attr is SetStatusAttribute)
         {
             (attr as SetStatusAttribute).UpdateStatus(cache, row, row.Hold);
         }
     }
 }
 public static void RowInserted <Field>(PXCache sender, object data)
     where Field : IBqlField
 {
     foreach (PXEventSubscriberAttribute attr in sender.GetAttributes <Field>(data))
     {
         if (attr is CADailyAccumulatorAttribute)
         {
             ((CADailyAccumulatorAttribute)attr).RowInserted(sender, new PXRowInsertedEventArgs(data, false));
         }
     }
 }
Пример #10
0
 private static TAtt GetAttribute <TAtt>(PXCache cache, string memberInfo)
     where TAtt : PXEventSubscriberAttribute
 {
     foreach (PXEventSubscriberAttribute attribute in cache.GetAttributes(memberInfo))
     {
         if (attribute is TAtt)
         {
             return((TAtt)attribute);
         }
     }
     return(null);
 }
Пример #11
0
 public static List <object> ChildSelect(PXCache cache, object row, Type ParentType)
 {
     foreach (PXEventSubscriberAttribute attr in cache.GetAttributes(null))
     {
         if (attr is PXParentAttribute && ((PXParentAttribute)attr).ParentType.IsAssignableFrom(ParentType))
         {
             PXView view = ((PXParentAttribute)attr).GetChildrenSelect(cache);
             return(view.SelectMultiBound(new object[] { row }));
         }
     }
     return(null);
 }
Пример #12
0
 public static object ParentSelect(PXCache cache, object row, Type ParentType)
 {
     foreach (PXEventSubscriberAttribute attr in cache.GetAttributes(null))
     {
         if (attr is PXParentAttribute && ((PXParentAttribute)attr).ParentType.IsAssignableFrom(ParentType))
         {
             PXView parentview = ((PXParentAttribute)attr).GetParentSelect(cache);
             return(parentview.SelectSingleBound(new object[] { row }));
         }
     }
     return(null);
 }
Пример #13
0
        private static void RemoveErrorWarning <TField>(PXCache cache, object entity, string errorMessage)
            where TField : IBqlField
        {
            var fieldName = cache.GetField(typeof(TField));
            var hasError  = cache.GetAttributes(entity, fieldName).OfType <IPXInterfaceField>()
                            .Any(x => x.ErrorText == errorMessage);

            if (hasError)
            {
                cache.ClearFieldErrors <TField>(entity);
            }
        }
Пример #14
0
 public static CATran DefaultValues <Field>(PXCache sender, object data)
     where Field : IBqlField
 {
     foreach (PXEventSubscriberAttribute attr in sender.GetAttributes <Field>(data))
     {
         if (attr is DepositDetailTranIDAttribute)
         {
             ((DepositDetailTranIDAttribute)attr)._IsIntegrityCheck = true;
             return(((DepositDetailTranIDAttribute)attr).DefaultValues(sender, new CATran(), data));
         }
     }
     return(null);
 }
Пример #15
0
 public static void SetLastNumberField <Field>(PXCache sender, object row, Type lastNumberField)
     where Field : IBqlField
 {
     foreach (PXEventSubscriberAttribute attribute in sender.GetAttributes <Field>(row))
     {
         if (attribute is AutoNumberAttribute)
         {
             AutoNumberAttribute attr = (AutoNumberAttribute)attribute;
             attr.LastNumberField = lastNumberField;
             attr.CreateLastNumberCommand();
         }
     }
 }
Пример #16
0
    protected void Page_Init(object sender, EventArgs e)
    {
        //if (this.form.TemplateContainer.Controls.Count <= 1) return;
        PXCache cache       = this.ds.DataGraph.Caches[typeof(FeaturesSet)];
        var     features    = new List <string>();
        var     disabled    = new List <string>();
        var     subfeatures = new Dictionary <string, List <string> >(StringComparer.InvariantCultureIgnoreCase);

        foreach (string field in cache.Fields)
        {
            string parentName   = null;
            bool   featureFound = false;


            var featureAttributes = cache.GetAttributes(null, field).OfType <FeatureAttribute>();
            foreach (FeatureAttribute feature in featureAttributes)
            {
                featureFound = feature.Visible;
                if (feature.Top != true && feature.Parent != null)
                {
                    parentName = feature.Parent.Name;
                }
            }

            if (!featureFound)
            {
                continue;
            }

            if (parentName != null)
            {
                if (!subfeatures.ContainsKey(parentName))
                {
                    subfeatures.Add(parentName, new List <string>());
                }
                subfeatures[parentName].Add(field);
            }
            else
            {
                features.Add(field);
            }

            if (PXAccess.FeatureReadOnly(field) || (parentName != null && PXAccess.FeatureReadOnly(parentName)))
            {
                disabled.Add(field);
            }
        }
        AddControls(0, features, subfeatures, disabled);
    }
        public static PXSetPropertyException VerifyingAndGetError <Field>(PXCache sender, object row) where Field : IBqlField
        {
            PXSetPropertyException err = null;

            foreach (PXSetPropertyException currentError in sender.GetAttributes <Field>(row).OfType <PXUIVerifyAttribute>()
                     .Select(attr => VerifyingAndGetError(attr, sender, row))
                     .Where(currentError => currentError != null))
            {
                switch (currentError.ErrorLevel)
                {
                case PXErrorLevel.RowError:
                    return(currentError);

                case PXErrorLevel.Error:
                case PXErrorLevel.RowWarning:
                    if (err == null || err.ErrorLevel != PXErrorLevel.Error)
                    {
                        err = currentError;
                    }
                    break;

                case PXErrorLevel.Warning:
                    if (err == null || err.ErrorLevel != PXErrorLevel.RowWarning)
                    {
                        err = currentError;
                    }
                    break;

                case PXErrorLevel.RowInfo:
                    if (err == null || err.ErrorLevel != PXErrorLevel.Warning)
                    {
                        err = currentError;
                    }
                    break;

                default:
                    err = currentError;
                    break;
                }
            }
            return(err);
        }
Пример #18
0
        public void RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            object lineNbr = sender.GetValue(e.Row, _lineNbr.Name);
            object lineRef = sender.GetValue(e.Row, _FieldName);
            int    length  = -1;

            if (lineRef == null)
            {
                foreach (PXEventSubscriberAttribute attribute in sender.GetAttributes(_FieldName))
                {
                    if (attribute is PXDBStringAttribute)
                    {
                        length = ((PXDBStringAttribute)attribute).Length;
                        break;
                    }
                }

                if (length > 0 && (int?)lineNbr > 0)
                {
                    sender.SetValue(e.Row, _FieldName, ((int?)lineNbr).Value.ToString().PadLeft(length, '0'));
                }
            }
        }
Пример #19
0
        public static string DumpAsTable <TItem>(this IReadOnlyCollection <TItem> items, PXCache cache)
        {
            PropertyInfo[] propertyInfos = typeof(TItem).GetProperties(BindingFlags.Instance | BindingFlags.Public)
                                           .Where(info => !ignoredFields.Contains(info.Name))
                                           .ToArray();

            Dictionary <string, int> maxValueLengths = new Dictionary <string, int>();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                int maxValueLength = 0;

                if (typeof(decimal?).IsAssignableFrom(propertyInfo.PropertyType))
                {
                    maxValueLength = decimal.MinValue.ToString(CultureInfo.InvariantCulture).Length;
                }
                else if (typeof(int?).IsAssignableFrom(propertyInfo.PropertyType))
                {
                    maxValueLength = int.MinValue.ToString(CultureInfo.InvariantCulture).Length;
                }
                else if (typeof(bool?).IsAssignableFrom(propertyInfo.PropertyType))
                {
                    maxValueLength = 5;
                }
                else if (propertyInfo.PropertyType == typeof(string))
                {
                    PXDBStringAttribute dbAttr = cache.GetAttributes(propertyInfo.Name).OfType <PXDBStringAttribute>().SingleOrDefault();

                    if (dbAttr != null)
                    {
                        maxValueLength = dbAttr.Length;
                    }
                    else
                    {
                        PXStringAttribute attr = cache.GetAttributes(propertyInfo.Name).OfType <PXStringAttribute>().SingleOrDefault();

                        if (attr != null)
                        {
                            maxValueLength = attr.Length;
                        }
                    }
                }
                else
                {
                    throw new Exception("Unexpected type");
                }

                maxValueLengths[propertyInfo.Name] = maxValueLength;
            }

            KeyValuePair <string, int>[] fieldsWithUnknownLength = maxValueLengths.Where(kvp => kvp.Value == 0).ToArray();

            string[] fieldsList = propertyInfos.Select(info => info.Name).ToArray();

            if (!fieldsWithUnknownLength.Any())
            {
                return(DumpAsTable <TItem>(items, cache, fieldsList, maxValueLengths));
            }

            foreach (TItem item in items)
            {
                foreach (KeyValuePair <string, int> kvp in fieldsWithUnknownLength)
                {
                    int?length = cache.GetValue(item, kvp.Key)?.ToString().Length;

                    if (length > maxValueLengths[kvp.Key])
                    {
                        maxValueLengths[kvp.Key] = length.Value;
                    }
                }
            }

            return(DumpAsTable <TItem>(items, cache, fieldsList, maxValueLengths));
        }
        private object GetFieldValue(PXCache sender, object row, Type field, bool disableLazyLoading, bool buildTranslations)
        {
            var dbLocalizableAttr = sender.GetAttributes(field.Name).FirstOrDefault(attr => attr is PXDBLocalizableStringAttribute);
            var listAttr          = IsListAttributeField(sender, field);

            if (!buildTranslations)
            {
                if (listAttr == 2)
                {
                    listAttr = 1;
                }
                dbLocalizableAttr = null;
            }

            if (disableLazyLoading)
            {
                if (listAttr == 0 && dbLocalizableAttr == null)
                {
                    return(sender.GetValue(row, field.Name));
                }
            }

            object       val   = sender.GetStateExt(row, field.Name);
            PXFieldState state = val as PXFieldState;

            if (state != null)
            {
                if (dbLocalizableAttr != null)
                {
                    var translations = sender.GetStateExt(row, field.Name + "Translations") as string[];
                    if (translations != null)
                    {
                        return(string.Join(" ", translations));
                    }
                }

                val = state.Value;
            }

            if (state is PXIntState)
            {
                PXIntState istate = (PXIntState)state;
                if (istate.AllowedValues != null && istate._NeutralLabels != null)
                {
                    for (int i = 0; i < istate.AllowedValues.Length && i < istate.AllowedLabels.Length && i < istate._NeutralLabels.Length; i++)
                    {
                        if (istate.AllowedValues[i] == (int)val)
                        {
                            if (listAttr == 2)
                            {
                                val = GetAllTranslations(sender, istate.Name, i, istate._NeutralLabels, istate.AllowedLabels);
                            }
                            else
                            {
                                val = istate.AllowedLabels[i];
                            }
                            break;
                        }
                    }
                }
            }
            else if (state is PXStringState)
            {
                PXStringState sstate = (PXStringState)state;
                if (sstate.AllowedValues != null && sstate._NeutralLabels != null)
                {
                    for (int i = 0; i < sstate.AllowedValues.Length && i < sstate.AllowedLabels.Length && i < sstate._NeutralLabels.Length; i++)
                    {
                        if (sstate.AllowedValues[i] == (string)val)
                        {
                            if (listAttr == 2)
                            {
                                val = GetAllTranslations(sender, sstate.Name, i, sstate._NeutralLabels, sstate.AllowedLabels);
                            }
                            else
                            {
                                val = sstate.AllowedLabels[i];
                            }
                            break;
                        }
                    }
                }
            }


            PXStringState strState = state as PXStringState;

            //Following is a hack to get FinPeriod to format as it is visible to the user... couldn't find any other way to do it ((.
            if (strState != null && strState.InputMask == "##-####")
            {
                string strFinPeriod = val.ToString();
                if (strFinPeriod.Length == 6)
                {
                    val = string.Format("{0}-{1}", strFinPeriod.Substring(0, 2), strFinPeriod.Substring(2, 4));
                }
            }


            return(val);
        }
 protected static Type GetCondition <AttrType>(PXCache sender, object row, string fieldName)
     where AttrType : PXBaseConditionAttribute
 {
     return(sender.GetAttributes(row, fieldName).OfType <AttrType>().Select(attr => (attr).Condition).FirstOrDefault());
 }
Пример #22
0
        private PXFieldState CreateFieldStateForFieldValue(object returnState, string entityType, string cacheName, string fieldName)
        {
            Type type = GraphHelper.GetType(entityType);

            if (type != null)
            {
                Type cachetype = GraphHelper.GetType(cacheName);
                if (cachetype == null)
                {
                    return(null);
                }

                PXCache cache = this.Caches[cachetype];
                PXDBAttributeAttribute.Activate(cache);
                PXFieldState state = cache.GetStateExt(null, fieldName) as PXFieldState;
                if (state != null)
                {
                    state.DescriptionName = null;
                }

                var attr = cache.GetAttributes(null, fieldName);

                if (attr != null)
                {
                    var timeListAttribute = attr.FirstOrDefault(a => a is PXTimeListAttribute) as PXTimeListAttribute;
                    var intAttribute      = attr.FirstOrDefault(a => a is PXIntAttribute) as PXIntAttribute;

                    if (timeListAttribute != null && intAttribute != null)
                    {
                        state = PXTimeState.CreateInstance((PXIntState)state, null, null);
                        state.SelectorMode = PXSelectorMode.Undefined;
                    }
                }

                if (state != null)
                {
                    if (returnState == null)
                    {
                        object item = cache.CreateInstance();
                        object newValue;
                        cache.RaiseFieldDefaulting(fieldName, item, out newValue);
                        if (newValue != null)
                        {
                            cache.RaiseFieldSelecting(fieldName, item, ref newValue, false);
                        }
                        state.Value = newValue;
                    }
                    else
                    {
                        state.Value = returnState;
                    }
                    state.Enabled = true;

                    PXView view;
                    if (state.ViewName != null &&
                        this.Views.TryGetValue(state.ViewName, out view) &&
                        view.BqlSelect.GetTables()[0] == typeof(EPEmployee))
                    {
                        state.ViewName = "Employee";
                    }
                }

                if (attr != null)
                {
                    var intListAttribute = attr.FirstOrDefault(a => a.GetType().IsSubclassOf(typeof(PXIntListAttribute))) as PXIntListAttribute;
                    if (intListAttribute != null)
                    {
                        return(state);
                    }
                }

                state = PXFieldState.CreateInstance((state as PXStringState)?.AllowedValues != null ? state : state.Value, state.DataType, state.PrimaryKey, state.Nullable, state.Required == true ? 1 : state.Required == null ? 0 : -1, state.Precision, state.Length, state.DefaultValue, fieldName,
                                                    state.DescriptionName, state.DisplayName, state.Error, state.ErrorLevel, true, true, false, PXUIVisibility.Visible, state.ViewName, state.FieldList, state.HeaderList);

                return(state);
            }
            return(null);
        }
Пример #23
0
        protected override void FieldSelectingHandler(PXCache sender, PXFieldSelectingEventArgs e)
        {
            if (!(e.Row is CSAnswers row))
            {
                return;
            }
            CRAttribute.Attribute attribute = CRAttribute.Attributes[row.AttributeID];
            System.Collections.Generic.List <CRAttribute.AttributeValue> values = attribute?.Values;
            bool?nullable1 = row.IsRequired;
            bool flag      = true;
            int  num1      = nullable1.GetValueOrDefault() == flag & nullable1.HasValue ? 1 : -1;

            if (values != null && values.Count > 0)
            {
                System.Collections.Generic.List <string> stringList1 = new System.Collections.Generic.List <string>();
                System.Collections.Generic.List <string> stringList2 = new System.Collections.Generic.List <string>();
                foreach (CRAttribute.AttributeValue attributeValue in values)
                {
                    if (!attributeValue.Disabled || !(row.Value != attributeValue.ValueID))
                    {
                        stringList1.Add(attributeValue.ValueID);
                        stringList2.Add(attributeValue.Description);
                    }
                }
                e.ReturnState = (object)PXStringState.CreateInstance(e.ReturnState, new int?(10), new bool?(true), typeof(CSAnswers.value).Name, new bool?(false), new int?(num1), attribute.EntryMask, stringList1.ToArray(), stringList2.ToArray(), new bool?(true), (string)null);
                int?controlType = attribute.ControlType;
                int num2        = 6;
                if (controlType.GetValueOrDefault() == num2 & controlType.HasValue)
                {
                    ((PXStringState)e.ReturnState).MultiSelect = true;
                }
            }
            else if (attribute != null)
            {
                int?nullable2 = attribute.ControlType;
                int num2      = 4;
                if (nullable2.GetValueOrDefault() == num2 & nullable2.HasValue)
                {
                    PXFieldSelectingEventArgs selectingEventArgs = e;
                    object      returnState = e.ReturnState;
                    System.Type dataType    = typeof(bool);
                    bool?       isKey       = new bool?(false);
                    bool?       nullable3   = new bool?(false);
                    int?        required    = new int?(num1);
                    nullable2 = new int?();
                    int?precision = nullable2;
                    nullable2 = new int?();
                    int?length = nullable2;
                    // ISSUE: variable of a boxed type
                    bool   local   = false;
                    string name    = typeof(CSAnswers.value).Name;
                    bool?  enabled = new bool?(true);
                    bool?  visible = new bool?(true);
                    nullable1 = new bool?();
                    bool?        readOnly = nullable1;
                    PXFieldState instance = PXFieldState.CreateInstance(returnState, dataType, isKey, nullable3, required, precision, length, (object)local, name, enabled: enabled, visible: visible, readOnly: readOnly, visibility: PXUIVisibility.Visible);
                    selectingEventArgs.ReturnState = (object)instance;
                    int result;
                    if (e.ReturnValue is string && int.TryParse((string)e.ReturnValue, NumberStyles.Integer, (IFormatProvider)CultureInfo.InvariantCulture, out result))
                    {
                        e.ReturnValue = (object)Convert.ToBoolean(result);
                    }
                }
                else
                {
                    nullable2 = attribute.ControlType;
                    int num3 = 5;
                    if (nullable2.GetValueOrDefault() == num3 & nullable2.HasValue)
                    {
                        e.ReturnState = (object)PXDateState.CreateInstance(e.ReturnState, typeof(CSAnswers.value).Name, new bool?(false), new int?(num1), attribute.EntryMask, attribute.EntryMask, new DateTime?(), new DateTime?());
                    }
                    else
                    {
                        PXStringState             stateExt           = sender.GetStateExt <CSAnswers.value>((object)null) as PXStringState;
                        PXFieldSelectingEventArgs selectingEventArgs = e;
                        object returnState = e.ReturnState;
                        int?   length      = new int?(stateExt.With <PXStringState, int>((Func <PXStringState, int>)(_ => _.Length)));
                        nullable1 = new bool?();
                        bool?        isUnicode       = nullable1;
                        string       name            = typeof(CSAnswers.value).Name;
                        bool?        isKey           = new bool?(false);
                        int?         required        = new int?(num1);
                        string       entryMask       = attribute.EntryMask;
                        bool?        exclusiveValues = new bool?(true);
                        PXFieldState instance        = PXStringState.CreateInstance(returnState, length, isUnicode, name, isKey, required, entryMask, (string[])null, (string[])null, exclusiveValues, (string)null);
                        selectingEventArgs.ReturnState = (object)instance;
                    }
                }
            }
            if (!(e.ReturnState is PXFieldState))
            {
                return;
            }
            PXFieldState      returnState1     = (PXFieldState)e.ReturnState;
            IPXInterfaceField pxInterfaceField = sender.GetAttributes((object)row, typeof(CSAnswers.value).Name).OfType <IPXInterfaceField>().FirstOrDefault <IPXInterfaceField>();

            if (pxInterfaceField != null && pxInterfaceField.ErrorLevel != PXErrorLevel.Undefined && !string.IsNullOrEmpty(pxInterfaceField.ErrorText))
            {
                returnState1.Error      = pxInterfaceField.ErrorText;
                returnState1.ErrorLevel = pxInterfaceField.ErrorLevel;
            }
            returnState1.Enabled = true;
        }
Пример #24
0
        public virtual void ARStatementCycle_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            ARStatementCycle row = (ARStatementCycle)e.Row;

            if (row.NextStmtDate.HasValue == false)
            {
                DateTime basisDate = row.LastStmtDate.HasValue? row.LastStmtDate.Value: Accessinfo.BusinessDate.HasValue? Accessinfo.BusinessDate.Value: DateTime.Now;
                row.NextStmtDate = CalcNextStatementDate(basisDate, row.PrepareOn, row.Day00, row.Day01);
            }
            ARSetup setup = this.ARSetup.Select();

            cache.GetAttributes(e.Row, null);
            if (setup.DefFinChargeFromCycle ?? false)
            {
                bool?hasOverdueInvoices    = null;
                bool hasUnAppliedPayments  = false;
                bool hasChargeableInvoices = false;
                if (row.RequirePaymentApplication ?? false)
                {
                    hasOverdueInvoices = CheckForOverdueInvoices(this, row.StatementCycleId, row.NextStmtDate.Value);
                    if (hasOverdueInvoices.Value)
                    {
                        if (CheckForOpenPayments(this, row.StatementCycleId))
                        {
                            hasUnAppliedPayments = true;
                        }
                    }
                }

                if ((row.FinChargeApply ?? false) && (row.RequireFinChargeProcessing ?? false))
                {
                    if (!hasOverdueInvoices.HasValue)
                    {
                        hasOverdueInvoices = CheckForOverdueInvoices(this, row.StatementCycleId, row.NextStmtDate.Value);
                    }
                    if (hasOverdueInvoices.Value &&
                        (!row.LastFinChrgDate.HasValue || row.LastFinChrgDate.Value < row.NextStmtDate.Value))
                    {
                        hasChargeableInvoices = true;
                    }
                }
                if (hasChargeableInvoices && hasUnAppliedPayments)
                {
                    this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                     new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsOverdueInvoicesAndUnappliedPayments, PXErrorLevel.RowWarning));
                }
                else
                {
                    if (hasChargeableInvoices)
                    {
                        this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                         new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsOverdueInvoices, PXErrorLevel.RowWarning));
                    }

                    if (hasUnAppliedPayments)
                    {
                        this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                         new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsUnappliedPayments, PXErrorLevel.RowWarning));
                    }
                }
            }
        }
Пример #25
0
        public virtual void ARStatementCycle_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }

            ARStatementCycle row = (ARStatementCycle)e.Row;

            if (row.NextStmtDate.HasValue == false)
            {
                DateTime basisDate = row.LastStmtDate.HasValue? row.LastStmtDate.Value: Accessinfo.BusinessDate.HasValue? Accessinfo.BusinessDate.Value: DateTime.Now;
                row.NextStmtDate = CalcNextStatementDate(basisDate, row.PrepareOn, row.Day00, row.Day01);
            }
            ARSetup setup = this.ARSetup.Select();

            PXCache.TryDispose(cache.GetAttributes(e.Row, null));

            if (CheckForUnprocessedPPD(this, row.StatementCycleId, row.NextStmtDate, null))
            {
                PXUIFieldAttribute.SetEnabled(cache, row, false);
                cache.RaiseExceptionHandling <FinPeriod.selected>(row, false,
                                                                  new PXSetPropertyException(Messages.UnprocessedPPDExists, PXErrorLevel.RowError));

                return;
            }

            bool?hasOverdueInvoices    = null;
            bool hasUnAppliedPayments  = false;
            bool hasChargeableInvoices = false;

            if (row.RequirePaymentApplication ?? false)
            {
                hasOverdueInvoices = CheckForOverdueInvoices(this, row.StatementCycleId, row.NextStmtDate.Value);
                if (hasOverdueInvoices.Value)
                {
                    if (CheckForOpenPayments(this, row.StatementCycleId))
                    {
                        hasUnAppliedPayments = true;
                    }
                }
            }

            // The third condition below conveys the 'hidden' meaning of
            // DefFinChargeFromCycle, i.e. 'attaching' overdue charges calculation
            // to statement cycles.
            //
            // If DefFinChargeFromCycle is false, it is assumed that the users take
            // care of overdue charges themselves and need not be warned.
            // -
            if ((row.FinChargeApply ?? false) &&
                (row.RequireFinChargeProcessing ?? false) &&
                (setup.DefFinChargeFromCycle ?? false))
            {
                if (!hasOverdueInvoices.HasValue)
                {
                    hasOverdueInvoices = CheckForOverdueInvoices(this, row.StatementCycleId, row.NextStmtDate.Value);
                }
                if (hasOverdueInvoices.Value &&
                    (!row.LastFinChrgDate.HasValue || row.LastFinChrgDate.Value < row.NextStmtDate.Value))
                {
                    hasChargeableInvoices = true;
                }
            }

            if (hasChargeableInvoices && hasUnAppliedPayments)
            {
                this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                 new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsOverdueInvoicesAndUnappliedPayments, PXErrorLevel.RowWarning));
            }
            else if (hasChargeableInvoices)
            {
                this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                 new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsOverdueInvoices, PXErrorLevel.RowWarning));
            }
            else if (hasUnAppliedPayments)
            {
                this.CyclesList.Cache.RaiseExceptionHandling <ARStatementCycle.statementCycleId>(row, row.StatementCycleId,
                                                                                                 new PXSetPropertyException(Messages.WRN_ProcessStatementDetectsUnappliedPayments, PXErrorLevel.RowWarning));
            }
        }