Exemplo n.º 1
0
        public static bool GenerarPartidas(RNOrdenRemision orden, string cvedoc, int folio, int numEmpresa, List <RNPartidasRecepcion> partidas, List <RNRecepcion.Lotes> lotes, out decimal cant_total, out decimal imp1, out decimal imp2, out decimal imp3, out decimal imp4, out decimal total, out decimal desc, out decimal descind, out decimal desfin)
        {
            RNConexion conexion = new RNConexion(numEmpresa);

            conexion.baseDatos.AbrirConexion();
            bool result = false;

            cant_total = 0;
            imp1       = 0;
            imp2       = 0;
            imp3       = 0;
            imp4       = 0;
            total      = 0;
            desc       = 0;
            descind    = 0;
            desfin     = 0;
            foreach (var p in partidas)
            {
                RNProducto prod     = RNProducto.ObtenerProductoPorClave(numEmpresa, p.CVE_ART);
                decimal    precio   = RNProducto.ObtenerPrecioProducto(p.CVE_ART, 1, numEmpresa);
                decimal    IMPU1    = 0.0M;
                decimal    IMPU2    = 0.0M;
                decimal    IMPU3    = 0.0M;
                decimal    IMPU4    = 0.0M;
                int        IMP1APLA = 0;
                int        IMP2APLA = 0;
                int        IMP3APLA = 0;
                int        IMP4APLA = 0;
                RNProducto.ObtenerImpuestos(p.CVE_ART, prod.CVE_ESQIMPU.Value, numEmpresa, out IMPU1, out IMPU2, out IMPU3, out IMPU4, out IMP1APLA, out IMP2APLA, out IMP3APLA, out IMP4APLA);
                cant_total += (precio * p.CANT);
                imp1       += precio * (IMPU1 / 100) * p.CANT;
                imp2       += precio * (IMPU2 / 100) * p.CANT;
                imp3       += precio * (IMPU3 / 100) * p.CANT;
                imp4       += precio * (IMPU4 / 100) * p.CANT;
                total      += (precio + imp1 + imp2 + imp3 + imp4) * p.CANT;
                desc       += 0;
                descind    += 0;
                desfin     += 0;
                conexion.baseDatos.LimpiarParametros();
                conexion.baseDatos.AgregarParametro("@CVE_DOC", cvedoc);
                conexion.baseDatos.AgregarParametro("@NUM_PAR", p.NUM_PAR);
                conexion.baseDatos.AgregarParametro("@CVE_ART", p.CVE_ART);
                conexion.baseDatos.AgregarParametro("@CANT", p.CANT);
                conexion.baseDatos.AgregarParametro("@PXS", p.CANT);
                conexion.baseDatos.AgregarParametro("@PREC", precio);
                conexion.baseDatos.AgregarParametro("@COST", p.COST);
                conexion.baseDatos.AgregarParametro("@IMPU1", IMPU1);
                conexion.baseDatos.AgregarParametro("@IMPU2", IMPU2);
                conexion.baseDatos.AgregarParametro("@IMPU3", IMPU3);
                conexion.baseDatos.AgregarParametro("@IMPU4", IMPU4);
                conexion.baseDatos.AgregarParametro("@IMP1APLA", IMP1APLA);
                conexion.baseDatos.AgregarParametro("@IMP2APLA", IMP2APLA);
                conexion.baseDatos.AgregarParametro("@IMP3APLA", IMP3APLA);
                conexion.baseDatos.AgregarParametro("@IMP4APLA", IMP4APLA);
                conexion.baseDatos.AgregarParametro("@TOTIMP1", IMP2APLA == 1 ? (precio * (IMPU1 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP2", IMP3APLA == 1 ? (precio * (IMPU2 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP3", IMP4APLA == 1 ? (precio * (IMPU3 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP4", IMP1APLA == 1 ? (precio * (IMPU4 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@DESC1", 0);
                conexion.baseDatos.AgregarParametro("@DESC2", 0);
                conexion.baseDatos.AgregarParametro("@DESC3", 0);
                conexion.baseDatos.AgregarParametro("@COMI", 0);
                conexion.baseDatos.AgregarParametro("@APAR", 0);
                conexion.baseDatos.AgregarParametro("@ACT_INV", "S");
                conexion.baseDatos.AgregarParametro("@NUM_ALM", p.NUM_ALM);
                conexion.baseDatos.AgregarParametro("@POLIT_APLI", "");
                conexion.baseDatos.AgregarParametro("@TIP_CAM", p.TIP_CAM);
                conexion.baseDatos.AgregarParametro("@UNI_VENTA", p.UNI_VENTA);
                conexion.baseDatos.AgregarParametro("@TIPO_PROD", p.TIPO_PROD);
                conexion.baseDatos.AgregarParametro("@CVE_OBS", 0);
                conexion.baseDatos.AgregarParametro("@REG_SERIE", 0);
                conexion.baseDatos.AgregarParametro("@E_LTPD", RNLbInventory.RegistrarEnlace(lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).reg_ltpd, lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).contador, numEmpresa));
                conexion.baseDatos.AgregarParametro("@TIPO_ELEM", "N");
                conexion.baseDatos.AgregarParametro("@NUM_MOV", RNLbInventory.RegistrarMovInveRemision(p, orden, lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).reg_ltpd, -1, numEmpresa));
                conexion.baseDatos.AgregarParametro("@TOT_PARTIDA", precio * p.CANT);
                conexion.baseDatos.AgregarParametro("@IMPRIMIR", "S");
                conexion.baseDatos.AgregarParametro("@UUID", "");
                conexion.baseDatos.AgregarParametro("@VERSION_SINC", DateTime.Today);
                conexion.baseDatos.AgregarParametro("@MAN_IEPS", p.MAN_IEPS);
                conexion.baseDatos.AgregarParametro("@APL_MAN_IMP", p.APL_MAN_IMP);
                conexion.baseDatos.AgregarParametro("@CUOTA_IEPS", p.CUOTA_IEPS);
                conexion.baseDatos.AgregarParametro("@APL_MAN_IEPS", p.APL_MAN_IEPS);
                conexion.baseDatos.AgregarParametro("@MTO_PORC", p.MTO_PORC);
                conexion.baseDatos.AgregarParametro("@MTO_CUOTA", p.MTO_CUOTA);
                conexion.baseDatos.AgregarParametro("@CVE_ESQ", p.CVE_ESQ);
                conexion.baseDatos.AgregarParametro("@DESCR_ART", p.DESCR_ART);
                result = conexion.baseDatos.EjecutarSinConsulta("insert into PAR_FACTR{0} (CVE_DOC,NUM_PAR,CVE_ART,CANT,PXS,PREC,COST,IMPU1,IMPU2,IMPU3,IMPU4,IMP1APLA,IMP2APLA,IMP3APLA,IMP4APLA,TOTIMP1,TOTIMP2,TOTIMP3,TOTIMP4,DESC1,DESC2,DESC3,COMI,APAR,ACT_INV,NUM_ALM,POLIT_APLI,TIP_CAM,UNI_VENTA,TIPO_PROD,CVE_OBS,REG_SERIE,E_LTPD,TIPO_ELEM,NUM_MOV,TOT_PARTIDA,IMPRIMIR,UUID,VERSION_SINC,MAN_IEPS,APL_MAN_IMP,CUOTA_IEPS,APL_MAN_IEPS,MTO_PORC,MTO_CUOTA,CVE_ESQ,DESCR_ART) values " +
                                                                "(@CVE_DOC,@NUM_PAR,@CVE_ART,@CANT,@PXS,@PREC,@COST,@IMPU1,@IMPU2,@IMPU3,@IMPU4,@IMP1APLA,@IMP2APLA,@IMP3APLA,@IMP4APLA,@TOTIMP1,@TOTIMP2,@TOTIMP3,@TOTIMP4,@DESC1,@DESC2,@DESC3,@COMI,@APAR,@ACT_INV,@NUM_ALM,@POLIT_APLI,@TIP_CAM,@UNI_VENTA,@TIPO_PROD,@CVE_OBS,@REG_SERIE,@E_LTPD,@TIPO_ELEM,@NUM_MOV,@TOT_PARTIDA,@IMPRIMIR,@UUID,@VERSION_SINC,@MAN_IEPS,@APL_MAN_IMP,@CUOTA_IEPS,@APL_MAN_IEPS,@MTO_PORC,@MTO_CUOTA,@CVE_ESQ,@DESCR_ART)") > 0;
                bool b = InsertarPartidasCL(cvedoc, p.NUM_PAR, numEmpresa);
            }
            return(result);
        }
        public bool InsertarPartidas(List <RNPartidasRecepcion> partidas, string cveDoc, int folio, List <Lotes> lotes, int numEmpresa, out decimal cant_total, out decimal imp1, out decimal imp2, out decimal imp3, out decimal imp4, out decimal total, out decimal desc, out decimal descind, out decimal desfin)
        {
            cant_total = 0;
            imp1       = 0;
            imp2       = 0;
            imp3       = 0;
            imp4       = 0;
            total      = 0;
            desc       = 0;
            descind    = 0;
            desfin     = 0;
            RNConexion conexion = new RNConexion(numEmpresa);

            conexion.baseDatos.AbrirConexion();
            bool result = false;

            foreach (var p in partidas)
            {
                RNProducto prod     = RNProducto.ObtenerProductoPorClave(numEmpresa, p.CVE_ART);
                decimal    precio   = RNProducto.ObtenerPrecioProducto(p.CVE_ART, 1, numEmpresa);
                decimal    IMPU1    = 0.0M;
                decimal    IMPU2    = 0.0M;
                decimal    IMPU3    = 0.0M;
                decimal    IMPU4    = 0.0M;
                int        IMP1APLA = 0;
                int        IMP2APLA = 0;
                int        IMP3APLA = 0;
                int        IMP4APLA = 0;
                if (prod.CVE_ESQIMPU.Value > 0 && prod.CVE_ESQIMPU != null)
                {
                    RNProducto.ObtenerImpuestos(p.CVE_ART, prod.CVE_ESQIMPU.Value, numEmpresa, out IMPU1, out IMPU2, out IMPU3, out IMPU4, out IMP1APLA, out IMP2APLA, out IMP3APLA, out IMP4APLA);
                }
                cant_total += (prod.ULT_COSTO.Value * p.CANT);
                imp1       += prod.ULT_COSTO.Value * (IMPU1 / 100) * p.CANT;
                imp2       += prod.ULT_COSTO.Value * (IMPU2 / 100) * p.CANT;
                imp3       += prod.ULT_COSTO.Value * (IMPU3 / 100) * p.CANT;
                imp4       += prod.ULT_COSTO.Value * (IMPU4 / 100) * p.CANT;
                total      += (prod.ULT_COSTO.Value * p.CANT) + imp1 + imp2 + imp3 + imp4;
                desc       += 0;
                descind    += 0;
                desfin     += 0;
                conexion.baseDatos.LimpiarParametros();
                conexion.baseDatos.AgregarParametro("@CVE_DOC", p.CVE_DOC);
                conexion.baseDatos.AgregarParametro("@NUM_PAR", p.NUM_PAR);
                conexion.baseDatos.AgregarParametro("@CVE_ART", p.CVE_ART);
                conexion.baseDatos.AgregarParametro("@CANT", p.CANT);
                conexion.baseDatos.AgregarParametro("@PXR", p.PXR);
                conexion.baseDatos.AgregarParametro("@PREC", precio);
                conexion.baseDatos.AgregarParametro("@COST", prod.ULT_COSTO);
                conexion.baseDatos.AgregarParametro("@IMPU1", IMPU1);
                conexion.baseDatos.AgregarParametro("@IMPU2", IMPU2);
                conexion.baseDatos.AgregarParametro("@IMPU3", IMPU3);
                conexion.baseDatos.AgregarParametro("@IMPU4", IMPU4);
                conexion.baseDatos.AgregarParametro("@IMP1APLA", IMP1APLA);
                conexion.baseDatos.AgregarParametro("@IMP2APLA", IMP2APLA);
                conexion.baseDatos.AgregarParametro("@IMP3APLA", IMP3APLA);
                conexion.baseDatos.AgregarParametro("@IMP4APLA", IMP4APLA);
                conexion.baseDatos.AgregarParametro("@TOTIMP2", IMP2APLA == 1?(prod.ULT_COSTO * (IMPU1 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP3", IMP3APLA == 1?(prod.ULT_COSTO * (IMPU2 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP4", IMP4APLA == 1?(prod.ULT_COSTO * (IMPU3 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@TOTIMP1", IMP1APLA == 1?(prod.ULT_COSTO * (IMPU4 / 100)) * p.CANT : 0.00M);
                conexion.baseDatos.AgregarParametro("@DESCU", p.DESCU);
                conexion.baseDatos.AgregarParametro("@ACT_INV", p.ACT_INV);
                conexion.baseDatos.AgregarParametro("@TIP_CAM", p.TIP_CAM);
                conexion.baseDatos.AgregarParametro("@UNI_VENTA", p.UNI_VENTA);
                conexion.baseDatos.AgregarParametro("@TIPO_ELEM", p.TIPO_ELEM);
                conexion.baseDatos.AgregarParametro("@TIPO_PROD", p.TIPO_PROD);
                conexion.baseDatos.AgregarParametro("@CVE_OBS", p.CVE_OBS);
                conexion.baseDatos.AgregarParametro("@E_LTPD", RNLbInventory.RegistrarEnlace(lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).reg_ltpd, lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).contador, numEmpresa));
                conexion.baseDatos.AgregarParametro("@REG_SERIE", p.REG_SERIE);
                conexion.baseDatos.AgregarParametro("@FACTCONV", p.FACTCONV);
                conexion.baseDatos.AgregarParametro("@COST_DEV", prod.ULT_COSTO);
                conexion.baseDatos.AgregarParametro("@NUM_ALM", p.NUM_ALM);
                conexion.baseDatos.AgregarParametro("@MINDIRECTO", p.MINDIRECTO);
                conexion.baseDatos.AgregarParametro("@NUM_MOV", RNLbInventory.RegistrarMovInveRemision(p, RNOrdenRemision.ObtenerRemision(cveDoc, numEmpresa), lotes.FirstOrDefault(x => x.partida == p.NUM_PAR).reg_ltpd, 1, numEmpresa));
                conexion.baseDatos.AgregarParametro("@TOT_PARTIDA", prod.ULT_COSTO * p.CANT);
                conexion.baseDatos.AgregarParametro("@MAN_IEPS", p.MAN_IEPS);
                conexion.baseDatos.AgregarParametro("@APL_MAN_IMP", p.APL_MAN_IMP);
                conexion.baseDatos.AgregarParametro("@CUOTA_IEPS", p.CUOTA_IEPS);
                conexion.baseDatos.AgregarParametro("@APL_MAN_IEPS", p.APL_MAN_IEPS);
                conexion.baseDatos.AgregarParametro("@MTO_PORC", p.MTO_PORC);
                conexion.baseDatos.AgregarParametro("@MTO_CUOTA", p.MTO_CUOTA);
                conexion.baseDatos.AgregarParametro("@CVE_ESQ", p.CVE_ESQ);
                conexion.baseDatos.AgregarParametro("@DESCR_ART", p.DESCR_ART);
                result = conexion.baseDatos.EjecutarSinConsulta("insert into PAR_COMPR{0} (CVE_DOC,NUM_PAR,CVE_ART,CANT,PXR,PREC,COST,IMPU1,IMPU2,IMPU3,IMPU4,IMP1APLA,IMP2APLA,IMP3APLA,IMP4APLA,TOTIMP1,TOTIMP2,TOTIMP3,TOTIMP4,DESCU,ACT_INV,TIP_CAM,UNI_VENTA,TIPO_ELEM,TIPO_PROD,CVE_OBS,E_LTPD,REG_SERIE,FACTCONV,COST_DEV,NUM_ALM,MINDIRECTO,NUM_MOV,TOT_PARTIDA,MAN_IEPS,APL_MAN_IMP,CUOTA_IEPS,APL_MAN_IEPS,MTO_PORC,MTO_CUOTA,CVE_ESQ,DESCR_ART) values " +
                                                                "(@CVE_DOC,@NUM_PAR,@CVE_ART,@CANT,@PXR,@PREC,@COST,@IMPU1,@IMPU2,@IMPU3,@IMPU4,@IMP1APLA,@IMP2APLA,@IMP3APLA,@IMP4APLA,@TOTIMP1,@TOTIMP2,@TOTIMP3,@TOTIMP4,@DESCU,@ACT_INV,@TIP_CAM,@UNI_VENTA,@TIPO_ELEM,@TIPO_PROD,@CVE_OBS,@E_LTPD,@REG_SERIE,@FACTCONV,@COST_DEV,@NUM_ALM,@MINDIRECTO,@NUM_MOV,@TOT_PARTIDA,@MAN_IEPS,@APL_MAN_IMP,@CUOTA_IEPS,@APL_MAN_IEPS,@MTO_PORC,@MTO_CUOTA,@CVE_ESQ,@DESCR_ART)") > 0;
            }
            bool abn = InsertarPartidasCL(partidas, numEmpresa);

            return(result);
        }