Esempio n. 1
0
        public static void ObtenerCartaCategoriasPdf(TruequeEntities db, CartaD cd, CartaV cv, List <DOCUMENTOP_CAT> con3, string decimales, bool fact, bool guardar,
                                                     ref int indexp,
                                                     ref List <string> armadoCuerpoTabStr,
                                                     ref int contadorTabla)
        {
            FormatosC format = new FormatosC();

            foreach (var item2 in con3)
            {
                if (guardar)
                {
                    int pos = db.CARTAs.Where(a => a.NUM_DOC.Equals(cv.num_doc)).OrderByDescending(a => a.POS).First().POS;
                    GuardarCartaPCategorias(db, cv, item2.MATKL, pos, ref indexp, fact, item2.VIGENCIA_DE.Value, item2.VIGENCIA_AL.Value);
                }
                if (cd != null || cv != null)
                {
                    DOCUMENTOP_MOD docmod = new DOCUMENTOP_MOD();
                    if (cv != null)
                    {
                        docmod = cv.DOCUMENTOP.FirstOrDefault(x => x.MATKL_ID == item2.MATKL);
                    }
                    if (cd != null)
                    {
                        docmod = new DOCUMENTOP_MOD
                        {
                            MONTO        = item2.MONTO,
                            PORC_APOYO   = item2.PORC_APOYO,
                            MONTO_APOYO  = item2.MONTO_APOYO,
                            PRECIO_SUG   = item2.PRECIO_SUG,
                            VOLUMEN_REAL = item2.VOLUMEN_REAL,
                            VOLUMEN_EST  = item2.VOLUMEN_EST,
                            APOYO_REAL   = item2.APOYO_REAL,
                            APOYO_EST    = item2.APOYO_EST
                        };
                    }
                    if ((cd != null && cd.material_x) || (cv != null && cv.material_x))
                    {
                        armadoCuerpoTabStr.Add("");
                    }
                    armadoCuerpoTabStr.Add(item2.MATKL);
                    MATERIALGP mt = db.MATERIALGPs.Where(x => x.ID == item2.MATKL).FirstOrDefault();//RSG 03.10.2018
                    if (mt != null)
                    {
                        armadoCuerpoTabStr.Add(mt.DESCRIPCION);//RSG 03.10.2018
                    }
                    else
                    {
                        armadoCuerpoTabStr.Add("");
                    }

                    if ((cd != null && cd.costoun_x) || (cv != null && cv.costoun_x))
                    {
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round(docmod.MONTO, 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                    }
                    if ((cd != null && cd.apoyo_x) || (cv != null && cv.apoyo_x))
                    {
                        armadoCuerpoTabStr.Add(format.toShowPorc(Math.Round(docmod.PORC_APOYO, 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                    }
                    if ((cd != null && cd.apoyop_x) || (cv != null && cv.apoyop_x))
                    {
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round(docmod.MONTO_APOYO, 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                    }

                    if ((cd != null && cd.costoap_x) || (cv != null && cv.costoap_x))
                    {
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round((docmod.MONTO - docmod.MONTO_APOYO), 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                    }
                    if ((cd != null && cd.precio_x) || (cv != null && cv.precio_x))
                    {
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round(docmod.PRECIO_SUG, 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                    }

                    //Volumen
                    //B20180726 MGC 2018.07.26
                    if ((cd != null && cd.volumen_x) || (cv != null && cv.volumen_x))
                    {
                        if (fact)
                        {
                            armadoCuerpoTabStr.Add(format.toShowNum(Math.Round(Convert.ToDecimal(docmod.VOLUMEN_REAL), 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                        }
                        else
                        {
                            armadoCuerpoTabStr.Add(format.toShowNum(Math.Round(Convert.ToDecimal(docmod.VOLUMEN_EST), 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                        }
                    }

                    //Apoyo
                    //B20180726 MGC 2018.07.26
                    if ((cd != null && cd.apoyototal_x) || (cv != null && cv.apoyototal_x))
                    {
                        if (fact)
                        {
                            armadoCuerpoTabStr.Add(format.toShow(Math.Round(Convert.ToDecimal(docmod.APOYO_REAL), 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                        }
                        else
                        {
                            armadoCuerpoTabStr.Add(format.toShow(Math.Round(Convert.ToDecimal(docmod.APOYO_EST), 2), decimales));//B20180730 MGC 2018.07.30 Formatos
                        }
                    }
                }
                else
                {
                    armadoCuerpoTabStr.Add("");
                    armadoCuerpoTabStr.Add(item2.MATKL);
                    armadoCuerpoTabStr.Add(item2.TXT50);
                    armadoCuerpoTabStr.Add(format.toShow(Math.Round(item2.MONTO, 2), decimales));          //B20180730 MGC 2018.07.30 Formatos
                    armadoCuerpoTabStr.Add(format.toShowPorc(Math.Round(item2.PORC_APOYO, 2), decimales)); //B20180730 MGC 2018.07.30 Formatos
                    armadoCuerpoTabStr.Add(format.toShow(Math.Round(item2.MONTO_APOYO, 2), decimales));    //B20180730 MGC 2018.07.30 Formatos
                    armadoCuerpoTabStr.Add(format.toShow(Math.Round(item2.RESTA, 2), decimales));          //B20180730 MGC 2018.07.30 Formatos
                    armadoCuerpoTabStr.Add(format.toShow(Math.Round(item2.PRECIO_SUG, 2), decimales));     //B20180730 MGC 2018.07.30 Formatos
                                                                                                           //B20180726 MGC 2018.07.26
                    if (fact)
                    {
                        armadoCuerpoTabStr.Add(format.toShowNum(Math.Round(Convert.ToDecimal(item2.VOLUMEN_REAL), 2), decimales)); //B20180730 MGC 2018.07.30 Formatos
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round(Convert.ToDecimal(item2.APOYO_REAL), 2), decimales));      //B20180730 MGC 2018.07.30 Formatos
                    }
                    else
                    {
                        armadoCuerpoTabStr.Add(format.toShowNum(Math.Round(Convert.ToDecimal(item2.VOLUMEN_EST), 2), decimales)); //B20180730 MGC 2018.07.30 Formatos
                        armadoCuerpoTabStr.Add(format.toShow(Math.Round(Convert.ToDecimal(item2.APOYO_EST), 2), decimales));      //B20180730 MGC 2018.07.30 Formatos
                    }
                }

                contadorTabla++;
            }
        }
Esempio n. 2
0
        public List <CategoriaMaterial> GrupoMateriales(string vkorg, string spart, string kunnr, string soc_id, string usuario_id)
        {
            if (kunnr == null)
            {
                kunnr = "";
            }

            Cadena cad = new Cadena();

            kunnr = cad.completaCliente(kunnr);

            List <DOCUMENTOM_MOD> jd = new List <DOCUMENTOM_MOD>();


            //Validar si hay materiales
            if (db.MATERIALs.Any(x => x.MATERIALGP_ID != null && x.ACTIVO.Value))
            {
                List <CLIENTE> clil = new List <CLIENTE>();
                try
                {
                    CLIENTE cli = db.CLIENTEs.Where(c => c.KUNNR == kunnr && c.VKORG == vkorg && c.SPART == spart).FirstOrDefault();

                    //Saber si el cliente es sold to, payer o un grupo
                    if (cli != null && cli.KUNNR != cli.PAYER && cli.KUNNR != cli.BANNER)
                    {
                        clil.Add(cli);
                    }
                }
                catch (Exception e)
                {
                    Log.ErrorLogApp(e, "Listas", "grupoMateriales");
                }
                var cie = clil;
                //Obtener el numero de periodos para obtener el historial
                int?mesesVenta = (db.CONFDIST_CAT.Any(x => x.SOCIEDAD_ID == soc_id) ? db.CONFDIST_CAT.First(x => x.SOCIEDAD_ID == soc_id).PERIODOS : null);
                int nummonths  = (mesesVenta != null ? mesesVenta.Value : DateTime.Now.Month);
                int imonths    = nummonths * -1;
                //Obtener el rango de los periodos incluyendo el año
                DateTime ff = DateTime.Today;
                DateTime fi = ff.AddMonths(imonths);

                string mi = fi.Month.ToString();
                string ai = fi.Year.ToString();

                string mf = ff.Month.ToString();
                string af = ff.Year.ToString();

                int aii = 0;
                int mii = 0;
                int aff = 0;
                int mff = 0;
                try
                {
                    aii = Convert.ToInt32(ai);
                    mii = Convert.ToInt32(mi);
                    aff = Convert.ToInt32(af);
                    mff = Convert.ToInt32(mf);
                }
                catch (Exception e)
                {
                    Log.ErrorLogApp(e, "Listas", "grupoMateriales-mesesVenta");
                }


                if (cie != null)
                {
                    jd = ListaMaterialGroupsMateriales(vkorg, spart, kunnr, soc_id, aii, mii, aff, mff, usuario_id);
                }
            }

            //Obtener las categorías
            var categorias = jd.GroupBy(c => c.ID_CAT, c => new { ID = c.ID_CAT.ToString(), DESC = c.DESC }).ToList();

            List <CategoriaMaterial> lcatmat = new List <CategoriaMaterial>();

            foreach (var item in categorias)
            {
                CategoriaMaterial cm = new CategoriaMaterial();
                cm.ID      = item.Key;
                cm.EXCLUIR = jd.FirstOrDefault(x => x.ID_CAT.Equals(item.Key)).EXCLUIR; //RSG 09.07.2018 ID167

                //Obtener los materiales de la categoría
                List <DOCUMENTOM_MOD> dl;
                List <DOCUMENTOM_MOD> dm = new List <DOCUMENTOM_MOD>();
                dl = jd.Where(c => c.ID_CAT == item.Key).Select(c => new DOCUMENTOM_MOD {
                    ID_CAT = c.ID_CAT, MATNR = c.MATNR, VAL = c.VAL, DESC = c.DESC
                }).ToList();                                                                                                                                         //Falta obtener el groupby

                //Obtener la descripción de los materiales
                foreach (DOCUMENTOM_MOD d in dl)
                {
                    DOCUMENTOM_MOD dcl;
                    dcl = dm.Where(z => z.MATNR == d.MATNR).Select(c => new DOCUMENTOM_MOD {
                        ID_CAT = c.ID_CAT, MATNR = c.MATNR, VAL = c.VAL, DESC = c.DESC
                    }).FirstOrDefault();

                    if (dcl == null)
                    {
                        DOCUMENTOM_MOD dcll = new DOCUMENTOM_MOD();
                        //No se ha agregado
                        decimal val = dl.Where(y => y.MATNR == d.MATNR).Sum(x => x.VAL);
                        dcll.ID_CAT = item.Key;
                        dcll.MATNR  = d.MATNR;

                        dcll.DESC    = d.DESC;
                        dcll.VAL     = val;
                        cm.TOTALCAT += val;//ADD RSG 22.11.2018

                        dm.Add(dcll);
                    }
                }

                cm.MATERIALES = dm;
                //LEJ 18.07.2018-----------------------------------------------------------
                MATERIALGP vv = FnCommon.ObtenerMaterialGroup(db, cm.ID);
                cm.UNICA       = vv.UNICA;
                cm.DESCRIPCION = vv.DESCRIPCION;
                lcatmat.Add(cm);
            }

            if (lcatmat.Count > 0)
            {
                CategoriaMaterial nnn = new CategoriaMaterial();
                nnn.ID          = "000";
                nnn.DESCRIPCION = FnCommon.ObtenerTotalProducts(db).TXT50;
                nnn.MATERIALES  = new List <DOCUMENTOM_MOD>();
                nnn.TOTALCAT    = 0;//ADD RSG 22.11.2018
                //foreach (var item in lcatmat)//RSG 09.07.2018 ID167
                foreach (var item in lcatmat.Where(x => !x.EXCLUIR).ToList())
                {
                    foreach (var ii in item.MATERIALES)
                    {
                        DOCUMENTOM_MOD dm = new DOCUMENTOM_MOD();
                        dm.ID_CAT     = "000";
                        dm.DESC       = ii.DESC;
                        dm.MATNR      = ii.MATNR;
                        dm.POR        = ii.POR;
                        dm.VAL        = ii.VAL;
                        nnn.TOTALCAT += ii.VAL;
                        nnn.MATERIALES.Add(dm);
                    }
                }
                //LEJ 18.07.2018-----------------------------------------------------------
                nnn.UNICA = FnCommon.ObtenerMaterialGroup(db, nnn.ID).UNICA;
                lcatmat.Add(nnn);
            }


            return(lcatmat);
        }
Esempio n. 3
0
        public JsonResult categoriasCliente(string vkorg, string spart, string kunnr, string soc_id)
        {
            TAT001Entities db  = new TAT001Entities();
            Cadena         cad = new Cadena();

            kunnr = cad.completaCliente(kunnr);
            if (kunnr == null)
            {
                kunnr = "";
            }

            //if (catid == null)
            //{
            //    catid = "";
            //}

            var jd = (dynamic)null;

            //Obtener los materiales
            IEnumerable <MATERIAL> matl = Enumerable.Empty <MATERIAL>();

            try
            {
                matl = db.MATERIALs.Where(m => m.ACTIVO == true);//.Select(m => m.ID).ToList();
            }
            catch (Exception e)
            {
            }

            var spras = Session["spras"].ToString();

            //Validar si hay materiales
            if (matl != null)
            {
                CLIENTE        cli  = new CLIENTE();
                List <CLIENTE> clil = new List <CLIENTE>();

                try
                {
                    cli = db.CLIENTEs.Where(c => c.KUNNR == kunnr & c.VKORG == vkorg & c.SPART == spart).FirstOrDefault();

                    //Saber si el cliente es sold to, payer o un grupo
                    if (cli != null)
                    {
                        //Es un soldto
                        if (cli.KUNNR != cli.PAYER && cli.KUNNR != cli.BANNER)
                        {
                            //cli.VKORG = cli.VKORG+" ";
                            clil.Add(cli);
                        }
                    }
                }
                catch (Exception e)
                {
                }

                var cie = clil.Cast <CLIENTE>();
                //    IEnumerable<CLIENTE> cie = clil as IEnumerable<CLIENTE>;
                //Obtener el numero de periodos para obtener el historial
                int nummonths = 3;
                int imonths   = nummonths * -1;
                //Obtener el rango de los periodos incluyendo el año
                DateTime ff = DateTime.Today;
                DateTime fi = ff.AddMonths(imonths);

                string mi = fi.Month.ToString(); //.ToString("MM");
                string ai = fi.Year.ToString();  //.ToString("yyyy");

                string mf = ff.Month.ToString(); // ("MM");
                string af = ff.Year.ToString();  // "yyyy");

                int aii = 0;
                try
                {
                    aii = Convert.ToInt32(ai);
                }
                catch (Exception e)
                {
                }

                int mii = 0;
                try
                {
                    mii = Convert.ToInt32(mi);
                }
                catch (Exception e)
                {
                }

                int aff = 0;
                try
                {
                    aff = Convert.ToInt32(af);
                }
                catch (Exception e)
                {
                }

                int mff = 0;
                try
                {
                    mff = Convert.ToInt32(mf);
                }
                catch (Exception e)
                {
                }

                if (cie != null)
                {
                    //Obtener el historial de compras de los clientesd
                    var matt = matl.ToList();
                    //kunnr = kunnr.TrimStart('0').Trim();
                    var pres = db.PRESUPSAPPs.Where(a => a.VKORG.Equals(vkorg) & a.SPART.Equals(spart) & a.KUNNR == kunnr & (a.GRSLS != null | a.NETLB != null)).ToList();
                    //var cat = db.MATERIALGPTs.Where(a => a.SPRAS_ID.Equals(spras)).ToList();
                    var cat = db.MATERIALGPs.Where(a => a.ACTIVO == true).ToList();//RSG 03.10.2018
                    //foreach (var c in cie)
                    //{
                    //    c.KUNNR = c.KUNNR.TrimStart('0').Trim();
                    //}

                    CONFDIST_CAT conf = getCatConf(soc_id);
                    if (conf != null)
                    {
                        if (conf.CAMPO == "GRSLS")
                        {
                            jd = (from ps in pres
                                  join cl in cie
                                  on ps.KUNNR equals cl.KUNNR
                                  join m in matt
                                  on ps.MATNR equals m.ID
                                  join mk in cat
                                  //on m.MATERIALGP_ID equals mk.MATERIALGP_ID
                                  on m.MATERIALGP_ID equals mk.ID                                       //RSG 03.10.2018
                                  where (ps.ANIO >= aii && ps.PERIOD >= mii) && (ps.ANIO <= aff && ps.PERIOD <= mff) &&
                                  (ps.VKORG == cl.VKORG && ps.VTWEG == cl.VTWEG && ps.SPART == cl.SPART //&& ps.VKBUR == cl.VKBUR &&
                                                                                                        //ps.VKGRP == cl.VKGRP && ps.BZIRK == cl.BZIRK
                                  ) && ps.BUKRS == soc_id &&
                                  ps.GRSLS > 0
                                  select new
                            {
                                m.MATERIALGP_ID,
                                //mk.TXT50//RSG 03.10.2018
                                TXT50 = mk.DESCRIPCION      //RSG 03.10.2018
                            }).ToList();
                        }
                        else
                        {
                            jd = (from ps in pres
                                  join cl in cie
                                  on ps.KUNNR equals cl.KUNNR
                                  join m in matt
                                  on ps.MATNR equals m.ID
                                  join mk in cat
                                  //on m.MATERIALGP_ID equals mk.MATERIALGP_ID
                                  on m.MATERIALGP_ID equals mk.ID                                       //RSG 03.10.2018
                                  where (ps.ANIO >= aii && ps.PERIOD >= mii) && (ps.ANIO <= aff && ps.PERIOD <= mff) &&
                                  (ps.VKORG == cl.VKORG && ps.VTWEG == cl.VTWEG && ps.SPART == cl.SPART //&& ps.VKBUR == cl.VKBUR &&
                                                                                                        //ps.VKGRP == cl.VKGRP && ps.BZIRK == cl.BZIRK
                                  ) && ps.BUKRS == soc_id &&
                                  ps.NETLB > 0
                                  select new
                            {
                                m.MATERIALGP_ID,
                                //mk.TXT50//RSG 03.10.2018
                                TXT50 = mk.DESCRIPCION      //RSG 03.10.2018
                            }).ToList();
                        }
                    }
                }
            }

            var list = new List <MATERIALGPT>();

            if (jd.Count > 0)
            {
                //MATERIALGPT c = db.MATERIALGPTs.Where(a => a.SPRAS_ID.Equals(spras) & a.MATERIALGP_ID.Equals("000")).FirstOrDefault();
                MATERIALGP c = db.MATERIALGPs.Where(a => a.ID.Equals("000")).FirstOrDefault();
                //MATERIALGPT cc = new MATERIALGPT();//B20180625 MGC 2018.07.02
                MATERIALGPT cc = new MATERIALGPT(); //B20180625 MGC 2018.07.02
                if (c != null)                      //B20180625 MGC 2018.07.02
                {
                    //cc.MATERIALGP_ID = "000";
                    //cc.SPRAS_ID = c.SPRAS_ID;
                    //cc.TXT50 = c.TXT50;
                    cc.MATERIALGP_ID = "000";
                    cc.SPRAS_ID      = "EN";
                    cc.TXT50         = c.DESCRIPCION;
                }
                else
                {
                    cc.MATERIALGP_ID = "000";
                }
                list.Add(cc);
            }

            foreach (var line in jd)
            {
                bool ban = true;
                foreach (var line2 in list)
                {
                    if (line.MATERIALGP_ID == line2.MATERIALGP_ID)
                    {
                        ban = false;
                    }
                }
                if (ban)
                {
                    MATERIALGPT c = new MATERIALGPT();
                    c.MATERIALGP_ID = line.MATERIALGP_ID;
                    c.TXT50         = line.TXT50;
                    list.Add(c);
                }
            }

            JsonResult jl = Json(list, JsonRequestBehavior.AllowGet);

            return(jl);
        }