public static void AddIntOrDateFilterOdDo(Filter filter, string valueOd, string valueDo, string field)
 {
     if (!valueOd.IsEmpty() && !valueDo.IsEmpty())
     {
         if (valueOd == valueDo)
         {
             filter.And(FilterElement.Eq(field, valueOd));
         }
         else
         {
             filter.And(FilterElement.GreaterThanOrEq(field, valueOd));
             filter.And(FilterElement.LessThanOrEq(field, valueDo));
         }
     }
 }
 public static void AddStringFilterOdDo(Filter filter, string valueOd, string valueDo, string field)
 {
     if (!valueOd.IsEmpty() && !valueDo.IsEmpty())
     {
         if (valueOd != valueDo)
         {
             //Príklad: <20.01; 20.06> - zoberie od  "20.01*" do "20.06*"
             filter.And(FilterElement.GreaterThanOrEq(field, valueOd));
             filter.And(Filter.OrElements(FilterElement.Like(field, string.Concat(valueDo, "%")),
                                          FilterElement.LessThanOrEq(field, valueDo)));
         }
         else
         {
             filter.And(FilterElement.Like(field, string.Concat(valueOd, "%")));
         }
     }
     else if (!valueOd.IsEmpty())
     {
         filter.And(FilterElement.Like(field, string.Concat(valueOd, "%")));
     }
 }
        public static byte GetHighDph(DateTime datum, out int dphRezim, IWebEasRepositoryBase repository)
        {
            byte dphHigh = 0;

            dphRezim = (int)repository.GetNastavenieI("reg", "RezimDph");
            if (dphRezim > 0) // 0 = neplatca; 1 = neplatca s evidenciou DPH na došlých dokladoch; 2 = mesačný platca; 4 = štvrťročný platca
            {
                // Nefungujuce riesenia: 1) nevedel vyskladat WHERE 2) Selectoval vsetky polia a filtroval az na BE
                // 1) repository.GetList<DphSadzbaView>(x => x.PlatnostOd <= DateTime.Today && x.PlatnostDo == null || x.PlatnostOd <= DateTime.Today && DateTime.Today <= x.PlatnostDo);
                // 2) repository.GetList<DphSadzbaView>().Where(x => x.PlatnostOd <= DateTime.Today && (x.PlatnostDo == null || DateTime.Today <= x.PlatnostDo));

                // az toto vytvorilo korektny SELECT
                var flt = new Filter();
                flt.And(FilterElement.LessThanOrEq("PlatnostOd", datum));
                flt.And(new Filter(FilterElement.Eq("PlatnostDo", null)).Or(FilterElement.GreaterThanOrEq("PlatnostDo", datum)));
                var selectedFields = new List <string>
                {
                    nameof(DphSadzbaView.DPH)
                };
                dphHigh = repository.GetList <DphSadzbaView>(flt, null, selectedFields: selectedFields).OrderByDescending(x => x.DPH).Take(1).FirstOrDefault().DPH;
            }
            return(dphHigh);
        }
        public static void UctDennik_BeforeGetList(IWebEasRepositoryBase repository, HierarchyNode node, ref string sql, ref Filter filter, ref string sqlFromAlias, string sqlOrderPart)
        {
            if (filter?.Parameters != null)
            {
                var  parameters = filter.Parameters;
                bool zau        = parameters.ContainsKey("ZAU");
                bool notZau     = parameters.ContainsKey("NOTZAU");
                bool cinnost    = parameters.ContainsKey("CINNOST");

                var newFilter = new Filter(nameof(UctDennikRptHelper.D_Tenant_Id), repository.Session.TenantIdGuid);

                if (parameters.ContainsKey(nameof(UctDennikRptHelper.Rok).ToUpper()))
                {
                    newFilter.AndEq(nameof(UctDennikRptHelper.Rok), parameters[nameof(UctDennikRptHelper.Rok).ToUpper()]);
                }

                AddIntOrDateFilterOdDo(
                    newFilter,
                    parameters.ContainsKey("OBDOBIEOD") ? parameters["OBDOBIEOD"].ToString() : string.Empty,
                    parameters.ContainsKey("OBDOBIEDO") ? parameters["OBDOBIEDO"].ToString() : string.Empty,
                    nameof(UctDennikRptHelper.UOMesiac));


                AddIntOrDateFilterOdDo(
                    newFilter,
                    parameters.ContainsKey("DATUMOD") ? parameters["DATUMOD"].ToString() : string.Empty,
                    parameters.ContainsKey("DATUMDO") ? parameters["DATUMDO"].ToString() : string.Empty,
                    nameof(UctDennikRptHelper.DatumUctovania));

                #region Hodnota Od - Do

                string valOd = parameters.ContainsKey("HODNOTAOD") ? parameters["HODNOTAOD"].ToString() : string.Empty;
                string valDo = parameters.ContainsKey("HODNOTADO") ? parameters["HODNOTADO"].ToString() : string.Empty;

                if (!string.IsNullOrEmpty(valDo) && (string.IsNullOrEmpty(valOd)))
                {
                    valOd = "0.001"; //Zmena zabezpečí aby sa rátalo od 0 do valDo a nebralo stranu na ktorej je 0.
                }

                if (!string.IsNullOrEmpty(valOd) && (string.IsNullOrEmpty(valDo) || valDo == "0" || valOd == valDo))
                {
                    newFilter.And(Filter.OrElements(FilterElement.Eq(nameof(UctDennikRptHelper.SumaMD), valOd),
                                                    FilterElement.Eq(nameof(UctDennikRptHelper.SumaDal), valOd)));
                }
                else if (!string.IsNullOrEmpty(valOd) && !string.IsNullOrEmpty(valDo))
                {
                    newFilter.And(Filter.OrElements(Filter.AndElements(FilterElement.GreaterThanOrEq(nameof(UctDennikRptHelper.SumaMD), valOd), FilterElement.LessThanOrEq(nameof(UctDennikRptHelper.SumaMD), valDo)),
                                                    Filter.AndElements(FilterElement.GreaterThanOrEq(nameof(UctDennikRptHelper.SumaDal), valOd), FilterElement.LessThanOrEq(nameof(UctDennikRptHelper.SumaDal), valDo))));
                }
                #endregion

                AddFilterForUcetByStringOrId(repository, newFilter, parameters);

                AddStringFilterOdDo(
                    newFilter,
                    parameters.ContainsKey("CISLOINTERNEOD") ? parameters["CISLOINTERNEOD"].ToString() : string.Empty,
                    parameters.ContainsKey("CISLOINTERNEDO") ? parameters["CISLOINTERNEDO"].ToString() : string.Empty,
                    nameof(UctDennikRptHelper.CisloInterne));

                if (!zau && notZau || zau && !notZau)
                {
                    newFilter.AndEq(nameof(UctDennikRptHelper.U), zau ? 1 : 0);
                }

                if (cinnost)
                {
                    newFilter.AndEq(nameof(UctDennikRptHelper.PodnCinn), (parameters["CINNOST"].ToString() == "2") ? 1 : 0);
                }

                AddFilterForIDsDkl(newFilter, parameters);
                AddFilterForIDsUct(newFilter, parameters);

                filter = AddNoDialogFilters(filter, newFilter, true);
            }
        }