Ejemplo n.º 1
0
        protected virtual void GLVoucherBatch_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            GLVoucherBatch row    = (GLVoucherBatch)e.Row;
            GLVoucherBatch oldRow = (GLVoucherBatch)e.OldRow;

            if (prevDirty == false)
            {
                bool nothingChanged = true;
                foreach (Type fieldType in sender.BqlFields)
                {
                    if (fieldType != typeof(GLVoucherBatch.selected))
                    {
                        string field = sender.GetField(fieldType);
                        if (!Equals(sender.GetValue(row, field), sender.GetValue(oldRow, field)))
                        {
                            nothingChanged = false;
                            break;
                        }
                    }
                }
                if (nothingChanged)
                {
                    sender.IsDirty = prevDirty;
                }
                else
                {
                    prevDirty = sender.IsDirty;
                }
            }
        }
        protected virtual void EPActivityApprove_ProjectID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            EPActivityApprove row = (EPActivityApprove)e.Row;

            if (row == null)
            {
                return;
            }

            if (Filter.Current.ProjectID != null)
            {
                e.NewValue = Filter.Current.ProjectID;
                e.Cancel   = true;
            }
            else
            {
                EPEarningType earningType = PXSelect <EPEarningType, Where <EPEarningType.typeCD, Equal <Required <EPEarningType.typeCD> > > > .Select(this, row.EarningTypeID);

                if (earningType != null && earningType.ProjectID != null && row.ProjectID == null &&
                    PXSelectorAttribute.Select(cache, e.Row, cache.GetField(typeof(EPActivityApprove.projectID)), earningType.ProjectID) != null                     //available in selector
                    )
                {
                    e.NewValue = earningType.ProjectID;
                    e.Cancel   = true;
                }
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 public void RowSelected(PXCache cache, PXRowSelectedEventArgs args)
 {
     if (args.Row != null && ShouldDisable)
     {
         var field      = cache.GetField(fieldType);
         var fieldValue = cache.GetValue(args.Row, field);
         PXUIFieldAttribute.SetEnabled(cache, args.Row, FieldName, fieldValue != null);
     }
 }
Ejemplo n.º 5
0
        public override object Evaluate(PXCache cache, object item, Dictionary <Type, object> pars)
        {
            Type    table      = BqlCommand.GetItemType(typeof(Field));
            PXCache cacheSetup = cache.Graph.Caches[table];
            string  fieldName  = cacheSetup.GetField(typeof(Field));

            object setup = new PXView(cache.Graph, true, BqlCommand.CreateInstance(typeof(Select <>), table)).SelectSingle();

            return(cacheSetup.GetValue(setup, fieldName));
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        private void RowUpdated(PXCache cache, PXRowUpdatedEventArgs args)
        {
            var field    = cache.GetField(fieldType);
            var oldValue = cache.GetValue(args.OldRow, field);
            var newValue = cache.GetValue(args.Row, field);

            if (!Equals(oldValue, newValue))
            {
                cache.SetValue(args.Row, FieldName, null);
                cache.RaiseExceptionHandling(FieldName, args.Row, null, null);
            }
        }
        protected override void OnProjectUpdated(PXCache cache, PXFieldUpdatedEventArgs args)
        {
            var projectFieldName = cache.GetField(projectField);
            var projectId        = cache.GetValue(args.Row, projectFieldName) as int?;

            if (DoesRequiredDefaultProjectTaskExist(cache.Graph, projectId) && NeedsPrefilling)
            {
                base.OnProjectUpdated(cache, args);
            }
            else
            {
                cache.SetValue(args.Row, _FieldName, null);
            }
        }
Ejemplo n.º 9
0
        private bool IsAnyFieldUpdated(PXCache cache, object newRow)
        {
            var original = cache.GetOriginal(newRow);

            foreach (var fieldType in cache.BqlFields)
            {
                var fieldName = cache.GetField(fieldType);
                var oldValue  = cache.GetValue(original, fieldName)?.ToString();
                var newValue  = cache.GetValue(newRow, fieldName)?.ToString();
                if (fieldName != _FieldName && oldValue != newValue)
                {
                    return(true);
                }
            }
            return(false);
        }
		public static IEnumerable<Type> GetDecimalFieldsAggregate<Table>(PXGraph graph)
			where Table : IBqlTable
		{
			var result = new List<Type> { };

			PXCache cache = graph.Caches[typeof(Table)];
			if (cache == null)
				throw new PXException(Messages.FailedToGetCache, typeof(Table).FullName);
			
			foreach (Type bqlField in cache.BqlFields
				.Where(fieldType => cache.GetAttributesReadonly(cache.GetField(fieldType)).OfType<PXDBDecimalAttribute>().Any()))
			{
				result.Add(typeof(Sum<,>));
				result.Add(bqlField);
			}

			return result;
		}
        protected virtual void EPActivityApprove_ProjectTaskID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            EPActivityApprove row = (EPActivityApprove)e.Row;

            if (row == null)
            {
                return;
            }

            if (Filter.Current.ProjectTaskID != null)
            {
                e.NewValue = Filter.Current.ProjectTaskID;
                e.Cancel   = true;
                return;
            }

            if (row.ParentTaskNoteID != null)
            {
                EPActivityApprove rowParentTask = PXSelect <EPActivityApprove> .Search <EPActivityApprove.noteID>(this, row.ParentTaskNoteID);

                if (rowParentTask != null && rowParentTask.ProjectID == row.ProjectID)
                {
                    e.NewValue = rowParentTask.ProjectTaskID;
                    e.Cancel   = true;
                }
            }

            EPEarningType earningRow = (EPEarningType)PXSelectorAttribute.Select <EPActivityApprove.earningTypeID>(cache, row);

            if (e.NewValue == null && earningRow != null && earningRow.ProjectID == row.ProjectID)
            {
                PMTask defTask = PXSelectorAttribute.Select(cache, e.Row, cache.GetField(typeof(EPTimeCardSummary.projectTaskID)), earningRow.TaskID) as PMTask;
                if (defTask != null && defTask.VisibleInEP == true)
                {
                    e.NewValue = earningRow.TaskID;
                    e.Cancel   = true;
                }
            }
        }
        public virtual TEntity Find(IDictionary itemValues)
        {
            foreach (var field in _keyFields)
            {
                object value = null;

                var fieldName = _cache.GetField(field);
                if (itemValues.Contains(fieldName))
                {
                    value = itemValues[fieldName];
                }
                else
                {
                    _cache.RaiseFieldDefaulting(fieldName, _template, out value);
                }
                if (value != null && !_cache.RaiseFieldUpdating(fieldName, _template, ref value))
                {
                    value = null;
                }
                _cache.SetValue(_template, field.Name, value);
            }
            return(Find(_template));
        }
Ejemplo n.º 13
0
        private void CheckFields(PXCache cache, object row, params Type[] fields)
        {
            var errors = new Dictionary <string, string>(fields.Length);

            foreach (Type field in fields)
            {
                var value = cache.GetValue(row, field.Name);
                if (value == null || (value is string && string.IsNullOrEmpty(value as string)))
                {
                    var state            = cache.GetValueExt(row, field.Name) as PXFieldState;
                    var fieldDisplayName = state == null || string.IsNullOrEmpty(state.DisplayName)
                                                ? field.Name
                                                : state.DisplayName;
                    var errorMessage = PXMessages.LocalizeFormatNoPrefix(Messages.EmptyValueErrorFormat, fieldDisplayName);
                    var fieldName    = cache.GetField(field);
                    errors.Add(fieldName, errorMessage);
                    PXUIFieldAttribute.SetError(cache, row, fieldName, errorMessage);
                }
            }
            if (errors.Count > 0)
            {
                throw new PXOuterException(errors, GetType(), row, ErrorMessages.RecordRaisedErrors, null, cache.GetItemType().Name);
            }
        }
Ejemplo n.º 14
0
        public override void RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            if ((e.Row as APTran) == null || sender.GetValue <APTran.tranType>(e.Row) as string != APDocType.Prepayment)
            {
                base.RowUpdated(sender, e);
                return;
            }

            AmountLineFields lineAmountsFields = GetDiscountDocumentLine(sender, e.Row);

            if (lineAmountsFields.FreezeManualDisc == true)
            {
                lineAmountsFields.FreezeManualDisc = false;
                return;
            }

            DiscountLineFields lineDiscountFields    = GetDiscountedLine(sender, e.Row);
            DiscountLineFields oldLineDiscountFields = GetDiscountedLine(sender, e.OldRow);

            if (lineDiscountFields.LineType == SOLineType.Discount)
            {
                return;
            }

            // Force auto mode.
            if (lineDiscountFields.ManualDisc == false && oldLineDiscountFields.ManualDisc == true)
            {
                sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.discPct)), 0m);
                sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.curyDiscAmt)), 0m);
                return;
            }

            if ((lineAmountsFields.CuryExtPrice ?? 0m) == 0)
            {
                sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.curyDiscAmt)), 0m);
                return;
            }

            LineEntitiesFields lineEntities         = LineEntitiesFields.GetMapFor(e.Row, sender);
            AmountLineFields   oldLineAmountsFields = GetDiscountDocumentLine(sender, e.OldRow);

            bool discountIsUpdated = false;

            if (lineDiscountFields.CuryDiscAmt != oldLineDiscountFields.CuryDiscAmt)
            {
                if (Math.Abs(lineDiscountFields.CuryDiscAmt ?? 0m) > Math.Abs(lineAmountsFields.CuryExtPrice.Value))
                {
                    sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.curyDiscAmt)), lineAmountsFields.CuryExtPrice);
                    PXUIFieldAttribute.SetWarning <DiscountLineFields.curyDiscAmt>(sender, e.Row,
                                                                                   PXMessages.LocalizeFormatNoPrefix(AR.Messages.LineDiscountAmtMayNotBeGreaterExtPrice, lineAmountsFields.ExtPriceDisplayName));
                }

                decimal?discPct = CalcDiscountPercent(lineAmountsFields, lineDiscountFields);

                sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.discPct)), discPct);
                discountIsUpdated = true;
            }
            else if (lineDiscountFields.DiscPct != oldLineDiscountFields.DiscPct ||
                     oldLineAmountsFields.CuryExtPrice != lineAmountsFields.CuryExtPrice)
            {
                decimal discAmt = CalcDiscountAmount(sender, GetLineDiscountTarget(sender, lineEntities),
                                                     lineAmountsFields, lineDiscountFields);

                sender.SetValueExt(e.Row, sender.GetField(typeof(DiscountLineFields.curyDiscAmt)), discAmt);
                discountIsUpdated = true;
            }

            if (discountIsUpdated || sender.Graph.IsCopyPasteContext)
            {
                sender.SetValue(e.Row, this.FieldName, true);                 // Switch to manual mode.
            }
        }
        protected virtual void CheckForSingleLocation(PXCache sender, INTran row)
        {
            InventoryItem item = (InventoryItem)PXSelectorAttribute.Select(sender, row, sender.GetField(typeof(INTran.inventoryID)));

            if (item != null && item.StkItem == true && row.TaskID != null && row.LocationID == null)
            {
                sender.RaiseExceptionHandling <INTran.locationID>(row, null, new PXSetPropertyException(Messages.RequireSingleLocation));
            }
        }
        protected virtual void CheckLocationTaskRule(PXCache sender, INTran row)
        {
            if (row.TaskID != null)
            {
                INLocation selectedLocation = (INLocation)PXSelectorAttribute.Select(sender, row, sender.GetField(typeof(INTran.locationID)));

                if (selectedLocation != null && selectedLocation.TaskID != row.TaskID)
                {
                    sender.RaiseExceptionHandling <INTran.locationID>(row, selectedLocation.LocationCD,
                                                                      new PXSetPropertyException(Messages.LocationIsMappedToAnotherTask, PXErrorLevel.Warning));
                }
            }
        }
Ejemplo n.º 17
0
        private bool IsMigratedRecord(PXCache cache, object data)
        {
            string fieldName = cache.GetField(IsMigratedRecordField);

            return((cache.GetValue(data, fieldName) as bool?) == true);
        }
Ejemplo n.º 18
0
        public static IEnumerable <Type> GetDecimalFieldsAggregate <Table>(PXGraph graph, bool closing)
            where Table : IBqlTable
        {
            var result = new List <Type> {
            };

            PXCache cache = graph.Caches[typeof(Table)];

            if (cache == null)
            {
                throw new PXException(Messages.FailedToGetCache, typeof(Table).FullName);
            }

            List <Type> decimalFields = cache.BqlFields
                                        .Where(fieldType => cache.GetAttributesReadonly(cache.GetField(fieldType)).OfType <PXDBDecimalAttribute>().Any() || cache.GetAttributesReadonly(cache.GetField(fieldType)).OfType <PXDBCalcedAttribute>().Any())
                                        .ToList();

            for (int i = 0; i < decimalFields.Count; i++)
            {
                bool lastField = (i + 1 == decimalFields.Count);
                Type bqlField  = decimalFields[i];
                result.Add(closing && lastField ? typeof(Sum <>) : typeof(Sum <,>));
                result.Add(bqlField);
            }

            return(result);
        }
Ejemplo n.º 19
0
        public virtual void RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            AmountLineFields lineAmountsFields = GetDiscountDocumentLine(sender, e.Row);

            if (lineAmountsFields.FreezeManualDisc == true)
            {
                lineAmountsFields.FreezeManualDisc = false;
                return;
            }

            DiscountLineFields lineDiscountFields = GetDiscountedLine(sender, e.Row);

            if (lineDiscountFields.LineType == SOLineType.Discount)
            {
                return;
            }

            AmountLineFields   oldLineAmountsFields  = GetDiscountDocumentLine(sender, e.OldRow);
            DiscountLineFields oldLineDiscountFields = GetDiscountedLine(sender, e.OldRow);

            LineEntitiesFields lineEntities    = LineEntitiesFields.GetMapFor(e.Row, sender);
            LineEntitiesFields oldLineEntities = LineEntitiesFields.GetMapFor(e.OldRow, sender);

            bool manualMode          = false;   //by default AutoMode.
            bool useDiscPct          = false;   //by default value in DiscAmt has higher priority than DiscPct when both are modified.
            bool keepDiscountID      = true;    //should be set to true if user changes discount code code manually
            bool manualDiscUnchecked = false;

            //Force Auto Mode
            if (lineDiscountFields.ManualDisc == false && oldLineDiscountFields.ManualDisc == true)
            {
                manualMode          = false;
                manualDiscUnchecked = true;
            }

            //Change to Manual Mode based on fields changed:
            if (lineDiscountFields.ManualDisc == true || sender.Graph.IsCopyPasteContext)
            {
                manualMode = true;
            }

            //if (row.IsFree == true && oldRow.IsFree != true)
            //    manualMode = true;

            if (lineDiscountFields.DiscPct != oldLineDiscountFields.DiscPct && lineEntities.InventoryID == oldLineEntities.InventoryID)
            {
                manualMode = true;
                useDiscPct = true;
            }

            //use DiscPct when only Quantity/CuryUnitPrice/CuryExtPrice was changed
            if (lineDiscountFields.DiscPct == oldLineDiscountFields.DiscPct && lineDiscountFields.CuryDiscAmt == oldLineDiscountFields.CuryDiscAmt &&
                (lineAmountsFields.Quantity != oldLineAmountsFields.Quantity || lineAmountsFields.CuryUnitPrice != oldLineAmountsFields.CuryUnitPrice || lineAmountsFields.CuryExtPrice != oldLineAmountsFields.CuryExtPrice))
            {
                useDiscPct = true;
            }

            if (lineDiscountFields.CuryDiscAmt != oldLineDiscountFields.CuryDiscAmt &&
                lineAmountsFields.Quantity == oldLineAmountsFields.Quantity && lineAmountsFields.CuryUnitPrice == oldLineAmountsFields.CuryUnitPrice)
            {
                manualMode = true;
                useDiscPct = false;
            }

            if (e.ExternalCall && (((Math.Abs((lineDiscountFields.CuryDiscAmt ?? 0m) - (oldLineDiscountFields.CuryDiscAmt ?? 0m)) > 0.0000005m) || (Math.Abs((lineDiscountFields.DiscPct ?? 0m) - (oldLineDiscountFields.DiscPct ?? 0m)) > 0.0000005m)) && lineDiscountFields.DiscountID == oldLineDiscountFields.DiscountID))
            {
                keepDiscountID = false;
            }

            //if only CuryLineAmt (Ext.Price) was changed for a line with DiscoutAmt<>0
            //for Contracts Qty * UnitPrice * Prorate(<>1) = ExtPrice
            if (lineAmountsFields.CuryLineAmount != oldLineAmountsFields.CuryLineAmount && lineAmountsFields.Quantity == oldLineAmountsFields.Quantity && lineAmountsFields.CuryUnitPrice == oldLineAmountsFields.CuryUnitPrice && lineAmountsFields.CuryExtPrice == oldLineAmountsFields.CuryExtPrice && lineDiscountFields.DiscPct == oldLineDiscountFields.DiscPct && lineDiscountFields.CuryDiscAmt == oldLineDiscountFields.CuryDiscAmt && lineDiscountFields.CuryDiscAmt != 0)
            {
                manualMode = true;
            }

            decimal?validLineAmtRaw;
            decimal?validLineAmt = null;

            if (lineAmountsFields.CuryLineAmount != oldLineAmountsFields.CuryLineAmount)
            {
                if (useDiscPct)
                {
                    decimal val = lineAmountsFields.CuryExtPrice ?? 0;

                    decimal disctAmt;
                    if (GetLineDiscountTarget(sender, lineEntities) == LineDiscountTargetType.SalesPrice)
                    {
                        disctAmt = PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * (lineAmountsFields.CuryUnitPrice ?? 0m), CMPrecision.TRANCURY)
                                   - PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * PXDBPriceCostAttribute.Round((lineAmountsFields.CuryUnitPrice ?? 0m) * (1 - (lineDiscountFields.DiscPct ?? 0m) * 0.01m)), CMPrecision.TRANCURY);
                    }
                    else
                    {
                        disctAmt = val * (lineDiscountFields.DiscPct ?? 0m) * 0.01m;
                        disctAmt = PXCurrencyAttribute.Round(sender, lineDiscountFields, disctAmt, CMPrecision.TRANCURY);
                    }

                    validLineAmtRaw = lineAmountsFields.CuryExtPrice - disctAmt;
                    validLineAmt    = PXCurrencyAttribute.Round(sender, lineAmountsFields, validLineAmtRaw ?? 0, CMPrecision.TRANCURY);
                }
                else
                {
                    if (lineDiscountFields.CuryDiscAmt > lineAmountsFields.CuryExtPrice)
                    {
                        validLineAmtRaw = lineAmountsFields.CuryExtPrice;
                    }
                    else
                    {
                        validLineAmtRaw = lineAmountsFields.CuryExtPrice - lineDiscountFields.CuryDiscAmt;
                    }
                    validLineAmt = PXCurrencyAttribute.Round(sender, lineAmountsFields, validLineAmtRaw ?? 0, CMPrecision.TRANCURY);
                }

                if (lineAmountsFields.CuryLineAmount != validLineAmt && lineDiscountFields.DiscPct != oldLineDiscountFields.DiscPct)
                {
                    manualMode = true;
                }
            }

            sender.SetValue(e.Row, this.FieldName, manualMode);

            //Process only Manual Mode:
            if (manualMode || sender.Graph.IsCopyPasteContext)
            {
                if (manualMode && !keepDiscountID && !sender.Graph.IsImport)
                {
                    lineDiscountFields.DiscountID         = null;
                    lineDiscountFields.DiscountSequenceID = null;
                }

                //Update related fields:
                if (lineAmountsFields.Quantity == 0 && oldLineAmountsFields.Quantity != 0)
                {
                    sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), 0m);
                    sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), 0m);
                }
                else if (lineAmountsFields.CuryLineAmount != oldLineAmountsFields.CuryLineAmount && !useDiscPct)
                {
                    decimal?extAmt  = lineAmountsFields.CuryExtPrice ?? 0;
                    decimal?lineAmt = lineAmountsFields.CuryLineAmount ?? 0;
                    if (extAmt - lineAmountsFields.CuryLineAmount >= 0)
                    {
                        if (lineDiscountFields.CuryDiscAmt > Math.Abs(extAmt ?? 0m))
                        {
                            sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), lineAmountsFields.CuryExtPrice);
                            PXUIFieldAttribute.SetWarning <DiscountLineFields.curyDiscAmt>(sender, e.Row,
                                                                                           PXMessages.LocalizeFormatNoPrefix(AR.Messages.LineDiscountAmtMayNotBeGreaterExtPrice, lineAmountsFields.ExtPriceDisplayName));
                        }
                        else
                        {
                            sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), extAmt - lineAmountsFields.CuryLineAmount);
                        }
                        if (extAmt != 0 && !sender.Graph.IsCopyPasteContext)
                        {
                            decimal?pct = 100 * lineDiscountFields.CuryDiscAmt / extAmt;
                            sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), pct);
                        }
                    }
                    else if (extAmt != 0 && !sender.Graph.IsCopyPasteContext)
                    {
                        if (lineDiscountFields.CuryDiscAmt != oldLineDiscountFields.CuryDiscAmt)
                        {
                            decimal?pct = 100 * lineDiscountFields.CuryDiscAmt / extAmt;
                            sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), (pct ?? 0m) < -100m ? -100m : pct);
                            if ((pct ?? 0m) < -100m)
                            {
                                sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), -lineAmountsFields.CuryExtPrice);
                                PXUIFieldAttribute.SetWarning <DiscountLineFields.curyDiscAmt>(sender, e.Row,
                                                                                               PXMessages.LocalizeFormatNoPrefix(AR.Messages.LineDiscountAmtMayNotBeGreaterExtPrice, lineAmountsFields.ExtPriceDisplayName));
                            }
                        }
                        else
                        {
                            sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), 0m);
                            sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), 0m);
                            sender.SetValueExt(e.Row, sender.GetField(typeof(curyLineAmt)), lineAmt);
                        }
                    }
                }
                else if (lineDiscountFields.CuryDiscAmt != oldLineDiscountFields.CuryDiscAmt)
                {
                    if (lineAmountsFields.CuryExtPrice != 0 && !sender.Graph.IsCopyPasteContext)
                    {
                        if (lineAmountsFields.CuryExtPrice != 0 && !sender.Graph.IsCopyPasteContext)
                        {
                            decimal?pct = (lineDiscountFields.CuryDiscAmt ?? 0) * 100 / lineAmountsFields.CuryExtPrice;
                            sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), pct);
                        }
                    }
                }
                else if (lineDiscountFields.DiscPct != oldLineDiscountFields.DiscPct)
                {
                    decimal val = lineAmountsFields.CuryExtPrice ?? 0;

                    decimal amt;
                    if (GetLineDiscountTarget(sender, lineEntities) == LineDiscountTargetType.SalesPrice)
                    {
                        if (lineAmountsFields.CuryUnitPrice != 0 && lineAmountsFields.Quantity != 0)//if sales price is available
                        {
                            amt = PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * (lineAmountsFields.CuryUnitPrice ?? 0m), CMPrecision.TRANCURY)
                                  - PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * PXDBPriceCostAttribute.Round((lineAmountsFields.CuryUnitPrice ?? 0m) * (1 - (lineDiscountFields.DiscPct ?? 0m) * 0.01m)), CMPrecision.TRANCURY);
                        }
                        else
                        {
                            amt = val * (lineDiscountFields.DiscPct ?? 0m) * 0.01m;
                        }
                    }
                    else
                    {
                        amt = val * (lineDiscountFields.DiscPct ?? 0m) * 0.01m;
                    }

                    sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), amt);
                }
                else if (validLineAmt != null && lineAmountsFields.CuryLineAmount != validLineAmt)
                {
                    decimal val = lineAmountsFields.CuryExtPrice ?? 0;

                    decimal amt;
                    if (GetLineDiscountTarget(sender, lineEntities) == LineDiscountTargetType.SalesPrice)
                    {
                        if (lineAmountsFields.CuryUnitPrice != 0 && lineAmountsFields.Quantity != 0)//if sales price is available
                        {
                            amt = PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * (lineAmountsFields.CuryUnitPrice ?? 0m), CMPrecision.TRANCURY)
                                  - PXCurrencyAttribute.Round(sender, lineAmountsFields, (lineAmountsFields.Quantity ?? 0m) * PXDBPriceCostAttribute.Round((lineAmountsFields.CuryUnitPrice ?? 0m) * (1 - (lineDiscountFields.DiscPct ?? 0m) * 0.01m)), CMPrecision.TRANCURY);
                        }
                        else
                        {
                            amt = val * (lineDiscountFields.DiscPct ?? 0m) * 0.01m;
                        }
                    }
                    else
                    {
                        amt = val * (lineDiscountFields.DiscPct ?? 0m) * 0.01m;
                    }

                    sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), amt);
                }
            }
            else if (manualDiscUnchecked && lineDiscountFields.DiscountID == null)
            {
                sender.SetValueExt(e.Row, sender.GetField(typeof(discPct)), 0m);
                sender.SetValueExt(e.Row, sender.GetField(typeof(curyDiscAmt)), 0m);
            }
        }
Ejemplo n.º 20
0
        public static object GetValue(this PXCache cache, object data, Type bqlField)
        {
            var fieldName = cache.GetField(bqlField);

            return(cache.GetValue(data, fieldName));
        }