Example #1
0
        //-----------------------------------
        //Genera Cargo Solicitud Colegiado
        //-----------------------------------
        public bool Ins_GenerarCargoSolicitud(string CodEmpresa, long TipoPrograma, long TipoSolicitud, string cPerCodigo, int nPeriodo, DateTime dFechaSys, string NroSolicitud)
        {
            bool exito = false;

            string NroRecibo = "";
            long   nLinea    = 0;
            //double nImporte = 0;

            //para Tipo de cambio
            double     nTC  = 0;
            BL_Sistema daTC = new BL_Sistema();

            //para CtaCteItem
            BL_CtaCteItem            blCCItem      = new BL_CtaCteItem();
            BL_CtaCteIteLine         blCCItemLine  = new BL_CtaCteIteLine();
            BL_CtaCteIteLinRetencion blCCRetencion = new BL_CtaCteIteLinRetencion();
            BL_ImpuestoServicio      blImpServ     = new BL_ImpuestoServicio();

            //para Obtener Serv. Configurado
            BE_ReqCtaCteSysConfigParamterServicio ReqServConfig = new BE_ReqCtaCteSysConfigParamterServicio();
            BL_CtaCteSysConfigParamterServicio    daServConfig  = new BL_CtaCteSysConfigParamterServicio();

            //actuliza solicitud con el recibo de cargo
            BL_Solicitud DaSolAdm = new BL_Solicitud();

            //----------------------
            //CommittableTransaction
            //----------------------
            Transaction            oldAmbient = Transaction.Current;
            CommittableTransaction committableTransaction;

            committableTransaction = oldAmbient as CommittableTransaction;

            if (committableTransaction == null)
            {
                committableTransaction = new CommittableTransaction();
                Transaction.Current    = committableTransaction;
            }

            try
            {
                //using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
                //{
                //
                ReqServConfig.cPerJurCodigo         = CodEmpresa;
                ReqServConfig.nSisModulo            = 7001;          //default aun falta definir interface
                ReqServConfig.nParCodigo_nProCodigo = TipoSolicitud; //CLng(CboPrograma.SelectedValue)
                ReqServConfig.cFLag = "FEC";

                if (daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows.Count > 0)
                {
                    DataRow row = daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows[0];
                    //--------------
                    //Tipo de cambio
                    //--------------
                    if (Convert.ToInt32(row["nMonCodigo"]) == 2) //Dolar
                    {
                        if (daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows.Count > 0)
                        {
                            //DataRow row = daTC.Get_TipodeCambio(ReqTC).Rows[0];
                            nTC = Convert.ToDouble(daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows[0]["nCompra"]);
                        }
                        else
                        {
                            throw new ApplicationException("No se ha registrado el Tipo de Cambio del dia: " + String.Format("{0:ddd, MMM d, yyyy}", dFechaSys));
                        }
                    }
                    else
                    {
                        nTC = 1.0;
                    }

                    //----------
                    //CtaCteItem
                    //----------
                    //se comente esto porque la Actualizacion 28/01/2014 no se necesita esta variable
                    //foreach (DataRow fila in daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows)
                    //{
                    //    //Obteniendo el total del importe de recibo (cabezera)
                    //    nImporte = nImporte + Convert.ToDouble(fila["nSysValor"]);
                    //}

                    //Actualizacion 28/01/2014:
                    //porque necesitan que cada concepto salga en diferente recibo
                    //NroRecibo = blCCItem.Ins_CtaCteItem(CodEmpresa, cPerCodigo, nPeriodo, row["nCtaCteTipoCta"].ToString(), dFechaSys.Year, nImporte, dFechaSys, 1);

                    //--------------
                    //CtaCteIteLine
                    //--------------
                    //Recorro SysConfParametrosServ
                    foreach (DataRow fila in daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows)
                    {
                        //aqui se cambio Actualizacion 28/01/2014:
                        NroRecibo = blCCItem.Ins_CtaCteItem(CodEmpresa, cPerCodigo, nPeriodo, row["nCtaCteTipoCta"].ToString(), dFechaSys.Year, Convert.ToDouble(fila["nSysValor"]), dFechaSys, 1);

                        nLinea = blCCItemLine.Ins_CtaCteIteLine(CodEmpresa, cPerCodigo, NroRecibo, Convert.ToInt32(fila["nParCodigo_nCtaCteSerCodigo"]), Convert.ToInt32(fila["nMonCodigo"]), 1, Convert.ToDouble(fila["nSysValor"]), Convert.ToDouble(fila["nSysValor"]), nTC, 1);

                        if (nLinea != 0)
                        {
                            //---------------------
                            //CtaCteIteLinRetencion
                            //---------------------
                            foreach (DataRow posicion in blImpServ.Get_ImpuestoServicio(CodEmpresa, cPerCodigo, NroRecibo, Convert.ToInt32(fila["nParCodigo_nCtaCteSerCodigo"]), 9256).Rows) //9256.- Perú
                            {
                                if (!blCCRetencion.Ins_CtaCteIteLinRetencion(CodEmpresa, cPerCodigo, NroRecibo, nLinea, Convert.ToInt32(posicion["nSysTasCodigo"]), Convert.ToDouble(fila["nSysValor"]), Convert.ToInt32(posicion["fSysTasValor"]), dFechaSys))
                                {
                                    throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLinRetencion.!");
                                }
                            }
                        }
                        else
                        {
                            throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLine.!");
                        }
                    }

                    //------------------------------------------------------------------------------
                    //update AdmSolicitud (cCtaCteRecibo) - Referenciando recibo en "AdmSolicitud" ?
                    //------------------------------------------------------------------------------
                    if (!DaSolAdm.Upd_AdmSol_cCtaCteRecibo(CodEmpresa, TipoPrograma, NroSolicitud, NroRecibo))
                    {
                        throw new ApplicationException("Se encontraron errores en la transaccion: AdmSolicitud.! " + CodEmpresa + ' ' + TipoPrograma + ' ' + NroSolicitud + ' ' + NroRecibo);
                    }

                    //exito = true;
                    //tx.Complete();

                    /* Perform transactional work here */
                    //No errors - commit transaction
                    committableTransaction.Commit();
                    exito = true;
                }

                else
                {
                    throw new ApplicationException("Configuracion de parametros no establecida.!");
                }
            }
            //}
            catch (Exception)
            {
                committableTransaction.Rollback();
                throw;
            }
            finally
            {
                committableTransaction.Dispose();
                //Restore the ambient transaction
                Transaction.Current = oldAmbient;
            }

            return(exito);
        }
        //----------------------
        //Agregar Item Recibo
        //----------------------
        public bool Ins_AgregarItemRecibo(string cPerJurCodigo, string cPerCodigo, string NroRecibo, long nCtaCteSerCodigo, DateTime dFechaSys, long nCantidad, double nPrecioUnit, double nImporte)
        {
            bool exito = false;
            long nLinea = 0;
            //para Tipo de cambio
            double nTC = 0;
            BL_Sistema daTC = new BL_Sistema();

            //para CtaCteIteLIne
            BL_CtaCteIteLine blCCItemLine = new BL_CtaCteIteLine();

            //para Obtener Serv.
            BE_ReqCtaCteServBusca ReqServ = new BE_ReqCtaCteServBusca();
            BL_CtaCtaServicio daServ = new BL_CtaCtaServicio();

            BL_ImpuestoServicio blImpServ = new BL_ImpuestoServicio();
            BL_CtaCteIteLinRetencion blCCRetencion = new BL_CtaCteIteLinRetencion();

            //Update CtaCteItem
            BL_CtaCteItem daCCItem = new BL_CtaCteItem();

            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
                {
                    ReqServ.cPerJurCodigo = cPerJurCodigo;
                    ReqServ.nCtaCteSerCodigo = nCtaCteSerCodigo;
                    ReqServ.nFlag = "SERV";

                    //
                    if (daServ.Get_CtaCteServicio(ReqServ).Rows.Count > 0)
                    {
                        DataRow row = daServ.Get_CtaCteServicio(ReqServ).Rows[0];
                        //--------------
                        //Tipo de cambio
                        //--------------
                        if (Convert.ToInt32(row["nMonCodigo"]) == 2) //Dolar
                        {
                            if (daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows.Count > 0)
                            {
                                //DataRow row = daTC.Get_TipodeCambio(ReqTC).Rows[0];
                                nTC = Convert.ToDouble(daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows[0]["nCompra"]);
                            }
                            else throw new ApplicationException("No se ha registrado el Tipo de Cambio del dia: " + String.Format("{0:ddd, MMM d, yyyy}", dFechaSys));
                        }
                        else nTC = 1.0;

                        //--------------
                        //CtaCteIteLine
                        //--------------
                        nLinea = blCCItemLine.Ins_CtaCteIteLine(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), Convert.ToInt32(row["nMonCodigo"]), nCantidad, nPrecioUnit, nImporte, nTC, 1);
                        if (nLinea != 0)
                        {
                            //---------------------
                            //CtaCteIteLinRetencion
                            //---------------------
                            foreach (DataRow posicion in blImpServ.Get_ImpuestoServicio(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), 9256).Rows) //9256.- Perú
                            {
                                if (!blCCRetencion.Ins_CtaCteIteLinRetencion(cPerJurCodigo, cPerCodigo, NroRecibo, nLinea, Convert.ToInt32(posicion["nSysTasCodigo"]), Convert.ToDouble(row["nCtaCteSerImpDef"]), Convert.ToInt32(posicion["fSysTasValor"]), dFechaSys))
                                {
                                    throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLinRetencion.!");
                                }
                            }
                        }
                        else throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLine.!");

                        //-----------------------------------
                        // Actulizar campo "nCtaCteImporte"
                        //-----------------------------------
                        if (!daCCItem.Upd_CtaCteItem_nCtaCteImpAplicado(cPerJurCodigo, NroRecibo, nImporte, "ADDITEM"))
                        {
                            throw new ApplicationException("Se encontraron errores en la transaccion: [Upd_CtaCteItem_nCtaCteImpAplicado].!");
                        }

                        exito = true;
                        tx.Complete();
                    }
                    else throw new ApplicationException("Configuracion de parametros no establecida.!");
                }
            }
            catch (Exception)
            {
                throw;
            }

            return exito;
        }
Example #3
0
        //----------------------
        //Agregar Item Recibo
        //----------------------
        public bool Ins_AgregarItemRecibo(string cPerJurCodigo, string cPerCodigo, string NroRecibo, long nCtaCteSerCodigo, DateTime dFechaSys, long nCantidad, double nPrecioUnit, double nImporte)
        {
            bool exito  = false;
            long nLinea = 0;
            //para Tipo de cambio
            double     nTC  = 0;
            BL_Sistema daTC = new BL_Sistema();

            //para CtaCteIteLIne
            BL_CtaCteIteLine blCCItemLine = new BL_CtaCteIteLine();

            //para Obtener Serv.
            BE_ReqCtaCteServBusca ReqServ = new BE_ReqCtaCteServBusca();
            BL_CtaCtaServicio     daServ  = new BL_CtaCtaServicio();

            BL_ImpuestoServicio      blImpServ     = new BL_ImpuestoServicio();
            BL_CtaCteIteLinRetencion blCCRetencion = new BL_CtaCteIteLinRetencion();

            //Update CtaCteItem
            BL_CtaCteItem daCCItem = new BL_CtaCteItem();

            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
                {
                    ReqServ.cPerJurCodigo    = cPerJurCodigo;
                    ReqServ.nCtaCteSerCodigo = nCtaCteSerCodigo;
                    ReqServ.nFlag            = "SERV";

                    //
                    if (daServ.Get_CtaCteServicio(ReqServ).Rows.Count > 0)
                    {
                        DataRow row = daServ.Get_CtaCteServicio(ReqServ).Rows[0];
                        //--------------
                        //Tipo de cambio
                        //--------------
                        if (Convert.ToInt32(row["nMonCodigo"]) == 2) //Dolar
                        {
                            if (daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows.Count > 0)
                            {
                                //DataRow row = daTC.Get_TipodeCambio(ReqTC).Rows[0];
                                nTC = Convert.ToDouble(daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows[0]["nCompra"]);
                            }
                            else
                            {
                                throw new ApplicationException("No se ha registrado el Tipo de Cambio del dia: " + String.Format("{0:ddd, MMM d, yyyy}", dFechaSys));
                            }
                        }
                        else
                        {
                            nTC = 1.0;
                        }

                        //--------------
                        //CtaCteIteLine
                        //--------------
                        nLinea = blCCItemLine.Ins_CtaCteIteLine(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), Convert.ToInt32(row["nMonCodigo"]), nCantidad, nPrecioUnit, nImporte, nTC, 1);
                        if (nLinea != 0)
                        {
                            //---------------------
                            //CtaCteIteLinRetencion
                            //---------------------
                            foreach (DataRow posicion in blImpServ.Get_ImpuestoServicio(cPerJurCodigo, cPerCodigo, NroRecibo, Convert.ToInt32(row["nCtaCteSerCodigo"]), 9256).Rows) //9256.- Perú
                            {
                                if (!blCCRetencion.Ins_CtaCteIteLinRetencion(cPerJurCodigo, cPerCodigo, NroRecibo, nLinea, Convert.ToInt32(posicion["nSysTasCodigo"]), Convert.ToDouble(row["nCtaCteSerImpDef"]), Convert.ToInt32(posicion["fSysTasValor"]), dFechaSys))
                                {
                                    throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLinRetencion.!");
                                }
                            }
                        }
                        else
                        {
                            throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLine.!");
                        }

                        //-----------------------------------
                        // Actulizar campo "nCtaCteImporte"
                        //-----------------------------------
                        if (!daCCItem.Upd_CtaCteItem_nCtaCteImpAplicado(cPerJurCodigo, NroRecibo, nImporte, "ADDITEM"))
                        {
                            throw new ApplicationException("Se encontraron errores en la transaccion: [Upd_CtaCteItem_nCtaCteImpAplicado].!");
                        }

                        exito = true;
                        tx.Complete();
                    }
                    else
                    {
                        throw new ApplicationException("Configuracion de parametros no establecida.!");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(exito);
        }
        //-----------------------------------
        //Genera Cargo Solicitud Colegiado
        //-----------------------------------
        public bool Ins_GenerarCargoSolicitud(string CodEmpresa, long TipoPrograma, long TipoSolicitud, string cPerCodigo, int nPeriodo, DateTime dFechaSys, string NroSolicitud)
        {
            bool exito = false;

            string NroRecibo = "";
            long nLinea = 0;
            //double nImporte = 0;

            //para Tipo de cambio
            double nTC = 0;
            BL_Sistema daTC = new BL_Sistema();

            //para CtaCteItem
            BL_CtaCteItem blCCItem = new BL_CtaCteItem();
            BL_CtaCteIteLine blCCItemLine = new BL_CtaCteIteLine();
            BL_CtaCteIteLinRetencion blCCRetencion = new BL_CtaCteIteLinRetencion();
            BL_ImpuestoServicio blImpServ = new BL_ImpuestoServicio();

            //para Obtener Serv. Configurado
            BE_ReqCtaCteSysConfigParamterServicio ReqServConfig = new BE_ReqCtaCteSysConfigParamterServicio();
            BL_CtaCteSysConfigParamterServicio daServConfig = new BL_CtaCteSysConfigParamterServicio();

            //actuliza solicitud con el recibo de cargo
            BL_Solicitud DaSolAdm = new BL_Solicitud();

            //----------------------
            //CommittableTransaction
            //----------------------
            Transaction oldAmbient = Transaction.Current;
            CommittableTransaction committableTransaction;
            committableTransaction = oldAmbient as CommittableTransaction;

            if (committableTransaction == null)
            {
                committableTransaction = new CommittableTransaction();
                Transaction.Current = committableTransaction;
            }

            try
            {
                //using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
                //{
                //
                ReqServConfig.cPerJurCodigo = CodEmpresa;
                ReqServConfig.nSisModulo = 7001; //default aun falta definir interface
                ReqServConfig.nParCodigo_nProCodigo = TipoSolicitud; //CLng(CboPrograma.SelectedValue)
                ReqServConfig.cFLag = "FEC";

                if (daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows.Count > 0)
                {
                    DataRow row = daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows[0];
                    //--------------
                    //Tipo de cambio
                    //--------------
                    if (Convert.ToInt32(row["nMonCodigo"]) == 2) //Dolar
                    {
                        if (daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows.Count > 0)
                        {
                            //DataRow row = daTC.Get_TipodeCambio(ReqTC).Rows[0];
                            nTC = Convert.ToDouble(daTC.Get_TipodeCambio(Convert.ToInt32(row["nMonCodigo"]), "TCD", String.Format("{0:dd/MM/yyyy}", dFechaSys), 0, 0).Rows[0]["nCompra"]);
                        }
                        else throw new ApplicationException("No se ha registrado el Tipo de Cambio del dia: " + String.Format("{0:ddd, MMM d, yyyy}", dFechaSys));
                    }
                    else nTC = 1.0;

                    //----------
                    //CtaCteItem
                    //----------
                    //se comente esto porque la Actualizacion 28/01/2014 no se necesita esta variable
                    //foreach (DataRow fila in daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows)
                    //{
                    //    //Obteniendo el total del importe de recibo (cabezera)
                    //    nImporte = nImporte + Convert.ToDouble(fila["nSysValor"]);
                    //}

                    //Actualizacion 28/01/2014:
                    //porque necesitan que cada concepto salga en diferente recibo
                    //NroRecibo = blCCItem.Ins_CtaCteItem(CodEmpresa, cPerCodigo, nPeriodo, row["nCtaCteTipoCta"].ToString(), dFechaSys.Year, nImporte, dFechaSys, 1);

                    //--------------
                    //CtaCteIteLine
                    //--------------
                    //Recorro SysConfParametrosServ
                    foreach (DataRow fila in daServConfig.Get_SysConfParametrosServ(ReqServConfig).Rows)
                    {
                        //aqui se cambio Actualizacion 28/01/2014:
                        NroRecibo = blCCItem.Ins_CtaCteItem(CodEmpresa, cPerCodigo, nPeriodo, row["nCtaCteTipoCta"].ToString(), dFechaSys.Year, Convert.ToDouble(fila["nSysValor"]), dFechaSys, 1);

                        nLinea = blCCItemLine.Ins_CtaCteIteLine(CodEmpresa, cPerCodigo, NroRecibo, Convert.ToInt32(fila["nParCodigo_nCtaCteSerCodigo"]), Convert.ToInt32(fila["nMonCodigo"]), 1, Convert.ToDouble(fila["nSysValor"]), Convert.ToDouble(fila["nSysValor"]), nTC, 1);

                        if (nLinea != 0)
                        {
                            //---------------------
                            //CtaCteIteLinRetencion
                            //---------------------
                            foreach (DataRow posicion in blImpServ.Get_ImpuestoServicio(CodEmpresa, cPerCodigo, NroRecibo, Convert.ToInt32(fila["nParCodigo_nCtaCteSerCodigo"]), 9256).Rows) //9256.- Perú
                            {
                                if (!blCCRetencion.Ins_CtaCteIteLinRetencion(CodEmpresa, cPerCodigo, NroRecibo, nLinea, Convert.ToInt32(posicion["nSysTasCodigo"]), Convert.ToDouble(fila["nSysValor"]), Convert.ToInt32(posicion["fSysTasValor"]), dFechaSys))
                                {
                                    throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLinRetencion.!");
                                }
                            }
                        }
                        else throw new ApplicationException("Se encontraron errores en la transaccion: Ins_CtaCteIteLine.!");
                    }

                    //------------------------------------------------------------------------------
                    //update AdmSolicitud (cCtaCteRecibo) - Referenciando recibo en "AdmSolicitud" ?
                    //------------------------------------------------------------------------------
                    if (!DaSolAdm.Upd_AdmSol_cCtaCteRecibo(CodEmpresa, TipoPrograma, NroSolicitud, NroRecibo))
                    {
                        throw new ApplicationException("Se encontraron errores en la transaccion: AdmSolicitud.! " + CodEmpresa + ' ' + TipoPrograma + ' ' + NroSolicitud + ' ' + NroRecibo);
                    }

                    //exito = true;
                    //tx.Complete();

                    /* Perform transactional work here */
                    //No errors - commit transaction
                    committableTransaction.Commit();
                    exito = true;
                }
                else throw new ApplicationException("Configuracion de parametros no establecida.!");
            }
            //}
            catch (Exception)
            {
                committableTransaction.Rollback();
                throw;
            }
            finally
            {
                committableTransaction.Dispose();
                //Restore the ambient transaction
                Transaction.Current = oldAmbient;
            }

            return exito;
        }