private static Type WhereByType(Type Filter, PXGraph graph, BqlCommand command, string[] excluded) { PXCache filter = graph.Caches[Filter]; Type where = typeof(Where <BQLConstants.BitOn, Equal <BQLConstants.BitOn> >); foreach (string field in filter.Fields.Where(field => (excluded == null || !excluded.Any(e => String.Compare(e, field, true) == 0)) && !filter.Fields.Contains(field + "Wildcard"))) { foreach (Type table in command.GetTables()) { PXCache cache = graph.Caches[table]; bool find = false; if (cache.Fields.Contains(field)) { Type sourceType = filter.GetBqlField(field); Type destinationType = cache.GetBqlField(field); if (sourceType != null && destinationType != null) { where = BqlCommand.Compose( typeof(Where2 <,>), typeof(Where <, ,>), typeof(Current <>), sourceType, typeof(IsNull), typeof(Or <,>), destinationType, typeof(Equal <>), typeof(Current <>), sourceType, typeof(And <>), where ); find = true; } } string f; if (field.Length > 8 && field.EndsWith("Wildcard") && cache.Fields.Contains(f = field.Substring(0, field.Length - 8))) { Type like = filter.GetBqlField(field); Type dest = cache.GetBqlField(f); where = BqlCommand.Compose( typeof(Where2 <,>), typeof(Where <, ,>), typeof(Current <>), like, typeof(IsNull), typeof(Or <,>), dest, typeof(Like <>), typeof(Current <>), like, typeof(And <>), where ); find = true; } if (find) { break; } } } return(where); }
private BqlCommand GetBqlCommand(PXCache cache) { var fieldType = cache.GetBqlField(_FieldName); return(BqlCommand.CreateInstance(typeof(Select <,>), BqlTable, typeof(Where <,>), fieldType, typeof(Equal <>), typeof(Required <>), fieldType)); }
public override void CacheAttached(PXCache sender) { base.CacheAttached(sender); if (sender.GetBqlField("CuryID") != null && (_Matches = CurrencyInfo.CuryIDStringAttribute.GetMatchesDictionary(sender)) != null) { sender.Graph.RowSelecting.AddHandler(sender.GetItemType(), RowSelectingCollectMatches); } }
public virtual decimal GetPerUnitTaxAmountForTaxableAdjustmentCalculation(Tax taxForTaxableAdustment, TaxDetail taxDetail, PXCache taxDetailCache, object row, PXCache rowCache, string curyTaxAmtFieldName, Func <List <object> > perUnitTaxSelector) { taxForTaxableAdustment.ThrowOnNull(nameof(taxForTaxableAdustment)); taxDetail.ThrowOnNull(nameof(taxDetail)); taxDetailCache.ThrowOnNull(nameof(taxDetailCache)); row.ThrowOnNull(nameof(row)); rowCache.ThrowOnNull(nameof(rowCache)); curyTaxAmtFieldName.ThrowOnNullOrWhiteSpace(nameof(curyTaxAmtFieldName)); perUnitTaxSelector.ThrowOnNull(nameof(perUnitTaxSelector)); if (taxForTaxableAdustment.TaxType == CSTaxType.PerUnit) { return(0m); } Type taxAmountField = taxDetailCache.GetBqlField(curyTaxAmtFieldName); List <object> allPerUnitTaxes = perUnitTaxSelector?.Invoke(); if (allPerUnitTaxes == null || allPerUnitTaxes.Count == 0) { return(0m); } var(perUnitInclusiveTaxes, perUnitLevel1Taxes) = GetNonExcludedPerUnitTaxesByCalculationLevel(allPerUnitTaxes); if (perUnitInclusiveTaxes.Count == 0 && perUnitLevel1Taxes.Count == 0) { return(0m); } switch (taxForTaxableAdustment.TaxCalcLevel) { case CSTaxCalcLevel.Inclusive when perUnitLevel1Taxes.Count > 0: PXTrace.WriteInformation(Messages.CombinationOfExclusivePerUnitTaxAndInclusveTaxIsForbiddenErrorMsg); throw new PXSetPropertyException(Messages.CombinationOfExclusivePerUnitTaxAndInclusveTaxIsForbiddenErrorMsg, PXErrorLevel.Error); case CSTaxCalcLevel.Inclusive: //The adjustment to taxable is amount of all per unit taxes. The level 1 per unit taxes are prohibited. return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, perUnitInclusiveTaxes, taxAmountField)); case CSTaxCalcLevel.CalcOnItemAmt: var allNonExcludedPerUnitTaxes = perUnitInclusiveTaxes.Concat(perUnitLevel1Taxes); return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, allNonExcludedPerUnitTaxes, taxAmountField)); case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt: // For level 2 taxes: // Taxable = LineAmt - InclusiveTaxAmt (including per unit inclusive taxes) + Level 1 Taxes amount (including per unit level 1 taxes) // Therefore, we need to add only the previously subtracted amount of inclusive per unit taxes return(SumTaxAmountsWithReverseAdjustment(taxDetailCache.Graph, perUnitInclusiveTaxes, taxAmountField)); default: return(0m); } }
public ISet <Type> GetDependencies(PXCache cache) { var res = new HashSet <Type>(); var field = cache.GetBqlField("CuryID"); if (field != null) { res.Add(field); } return(res); }
private Type GetBqlField(string source) { int splitIndex = source.IndexOf("__", StringComparison.InvariantCultureIgnoreCase); Type type = this.resultDefinition[0]; if (splitIndex != -1) { string sourceDac = source.Substring(0, splitIndex); source = source.Substring(splitIndex + 2); type = this.resultDefinition.First(_ => _.Name == sourceDac); } PXCache cache = graph.Caches[type]; Type bqlField = cache.GetBqlField(source); return(bqlField); }
protected virtual void CSAttribute_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { if (e.Row == null) { return; } var row = e.Row as CSAttribute; SetControlsState(row, sender); ValidateAttributeID(sender, row); if (row.ControlType == CSAttribute.GISelector) { if (!string.IsNullOrEmpty(row.ObjectName as string)) { try { Type objType = System.Web.Compilation.PXBuildManager.GetType(row.ObjectName, true); PXCache objCache = this.Caches[objType]; string[] fields = objCache.Fields .Where(f => objCache.GetBqlField(f) != null || f.EndsWith("_Attributes", StringComparison.OrdinalIgnoreCase)) .Where(f => !objCache.GetAttributesReadonly(f).OfType <PXDBTimestampAttribute>().Any()) .Where(f => !string.IsNullOrEmpty((objCache.GetStateExt(null, f) as PXFieldState)?.ViewName)) .Where(f => f != "CreatedByID" && f != "LastModifiedByID") .ToArray(); PXStringListAttribute.SetList <CSAttribute.fieldName>(sender, row, fields, fields); } catch { } } else { PXStringListAttribute.SetList <CSAttribute.fieldName>(sender, row, Array.Empty <string>(), Array.Empty <string>()); } } }
protected virtual void ValidateDimensionForKeyDuplication(Dimension dimension) { if (string.IsNullOrEmpty(dimension.ParentDimensionID)) { Dictionary <string, KeyValuePair <Type, string> > dictTables = PXDimensionAttribute.GetTables(dimension.DimensionID); if (dictTables != null) { foreach (string table in dictTables.Keys) { KeyValuePair <Type, string> pair = dictTables[table]; Type typeTable = pair.Key; PXCache cach = Caches[typeTable]; Type typeField = cach.GetBqlField(pair.Value); List <Type> keys = cach.BqlKeys; if (!keys.Contains(typeField)) { continue; } int line = 0; int count = (keys.Count - 1) * 2 + 1; Type[] group = new Type[count]; foreach (Type key in keys) { if (key != typeField) { group[line] = typeof(GroupBy <,>); group[line + 1] = key; line += 2; } } group[count - 1] = typeof(Count); Type groupby = BqlCommand.Compose(group); BqlCommand select = BqlCommand.CreateInstance (typeof(Select4 <,>), typeTable, typeof(Aggregate <>), typeof(GroupBy <,>), typeof(Left <,>), typeField, typeof(CurrentValue <>), typeof(Dimension.length), groupby ); PXView view = new PXView(this, false, select); List <object> rows = view.SelectMulti(null); foreach (PXResult row in rows) { if (row.RowCount > 1) { throw new PXRowPersistingException (typeof(Dimension.length).Name, dimension.Length, PXMessages.LocalizeFormatNoPrefixNLA(Messages.DimensionDuplicate, BqlCommand.GetTableName(typeTable)) ); } } } } } }