public override void GenerarEXCEL(string titulo = "")
        {
            DataRow  fila0;
            string   pathFile = "";
            string   pathPlantilla = "";
            string   cedulaRNC = "";
            string   periodo = "";
            string   tipoId = "", ncf = "", ncfModificado = "";
            DateTime fecha = DateTime.Now;
            string   feComprobante = "";
            double   itbis = 0, monto = 0;
            int      lineaNo = 12;


            OfficeDriver.ExcelDriver objExcel = null;

            try
            {
                if (MyData == null)
                {
                    return;
                }

                if (!objUtil.IsMSExcelIntalled())
                {
                    throw new Exception("MICROSOFT EXCEL NO ESTA INSTALADO...");
                }

                Cursor   = Cursors.WaitCursor;
                objExcel = new OfficeDriver.ExcelDriver();
                objExcel.isOpenOffice = false;

                //CREAMOS Directorio para Ubicar Archivos

                //Buscamos la Plantilla de excel
                pathPlantilla = System.Environment.CurrentDirectory + @"\Files\plantilla607.xls";
                if (!File.Exists(pathPlantilla))
                {
                    pathPlantilla = GetFolderDocGenerados("DGII") + @"\plantilla607.xls";
                }

                if (File.Exists(pathPlantilla))
                {
                    pathFile = GetFolderDocGenerados("DGII") + @"\temp_plantilla607.xls";
                    if (File.Exists(pathFile))
                    {
                        File.Delete(pathFile);
                    }

                    File.Copy(pathPlantilla, pathFile);
                }
                else
                {
                    objUtil.MostrarMensajeError("NO EXISTE PALNTILLA607.xls");
                    Cursor = Cursors.Default;
                    return;
                }

                tsProgressBar.Value   = 0;
                tsProgressBar.Maximum = MyData.Rows.Count + 1;
                tsProgressBar.Width   = 350;
                tsProgressBar.Step    = 1;
                tsProgressBar.Visible = true;

                fila0     = MyData.Rows[0];
                cedulaRNC = objUtil.GetAsString("EmpresaRNC", fila0).Replace("-", "").Trim();
                periodo   = objUtil.GetAsString("Periodo", fila0).Trim();

                //ABRIMOS EL ARCHIVO
                objExcel.OpenWorkBook(pathFile);

                objExcel.SetCellValue("C4", cedulaRNC);
                objExcel.SetCellValue("C5", periodo);
                objExcel.SetCellValue("C6", conteo);
                //objExcel.SetCellValue("C7", totalMonto);

                tsProgressBar.PerformStep();

                //EJECUTAMOS LA MACRO
                objExcel.RunMacro("'Formato607.cmdDataEntry_Click'");

                foreach (DataRow item in MyData.Rows)
                {
                    Cursor = Cursors.WaitCursor;

                    cedulaRNC     = objUtil.GetAsString("CedulaRNC", item).Replace("-", "").Trim();
                    tipoId        = objUtil.GetAsString("Tipo_Identificacion", item).Trim();
                    ncf           = objUtil.GetAsString("NCF", item).Trim();
                    ncfModificado = objUtil.GetAsString("NCF_Modificado", item).Trim();
                    fecha         = objUtil.GetAsDate("Fecha_Comprobante", item);
                    feComprobante = objUtil.DateToInt(fecha).ToString().Trim();

                    itbis = objUtil.GetAsDouble("Itbis", item);
                    monto = objUtil.GetAsDouble("Monto", item);

                    objExcel.SetCellValue("B" + lineaNo.ToString(), cedulaRNC);
                    objExcel.SetCellValue("C" + lineaNo.ToString(), tipoId);
                    objExcel.SetCellValue("D" + lineaNo.ToString(), ncf);
                    objExcel.SetCellValue("E" + lineaNo.ToString(), ncfModificado);
                    objExcel.SetCellValue("F" + lineaNo.ToString(), objUtil.GetAsString("Tipo_Ingreso_DGII", item));
                    objExcel.SetCellValue("G" + lineaNo.ToString(), feComprobante);

                    if (item["Fecha_Retencion"] is DBNull)
                    {
                        objExcel.SetCellValue("H" + lineaNo.ToString(), "");
                    }
                    else
                    {
                        fecha = objUtil.GetAsDate("Fecha_Retencion", item);
                        objExcel.SetCellValue("H" + lineaNo.ToString(), objUtil.DateToInt(fecha));
                    }
                    objExcel.SetCellValue("I" + lineaNo.ToString(), monto);
                    objExcel.SetCellValue("J" + lineaNo.ToString(), itbis);
                    objExcel.SetCellValue("K" + lineaNo.ToString(), objUtil.GetAsDouble("Itbis_Retenido", item));
                    objExcel.SetCellValue("L" + lineaNo.ToString(), objUtil.GetAsDouble("Itbis_Percibido", item));
                    objExcel.SetCellValue("M" + lineaNo.ToString(), objUtil.GetAsDouble("Retencion_Renta", item));
                    objExcel.SetCellValue("N" + lineaNo.ToString(), objUtil.GetAsDouble("ISR_Percibido", item));
                    objExcel.SetCellValue("O" + lineaNo.ToString(), objUtil.GetAsDouble("Impuesto_Selectivo_Consumo", item));
                    objExcel.SetCellValue("P" + lineaNo.ToString(), objUtil.GetAsDouble("Otros_Impuestos", item));
                    objExcel.SetCellValue("Q" + lineaNo.ToString(), objUtil.GetAsDouble("Propina_Legal", item));
                    objExcel.SetCellValue("R" + lineaNo.ToString(), objUtil.GetAsDouble("EnEfectivo", item));
                    objExcel.SetCellValue("S" + lineaNo.ToString(), objUtil.GetAsDouble("EnChequesODep", item));
                    objExcel.SetCellValue("T" + lineaNo.ToString(), objUtil.GetAsDouble("EnTarjeta", item));
                    objExcel.SetCellValue("U" + lineaNo.ToString(), objUtil.GetAsDouble("EnVentaACredito", item));
                    objExcel.SetCellValue("V" + lineaNo.ToString(), objUtil.GetAsDouble("EnBonos", item));
                    objExcel.SetCellValue("W" + lineaNo.ToString(), objUtil.GetAsDouble("EnPermuta", item));
                    objExcel.SetCellValue("X" + lineaNo.ToString(), objUtil.GetAsDouble("EnOtros", item));

                    tsProgressBar.PerformStep();

                    lineaNo++;

                    Cursor = Cursors.Default;
                }

                objExcel.ShowBook();
            }
            catch (Exception ex)
            {
                if (objExcel != null)
                {
                    objExcel.CloseBook();
                }
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                objExcel = null;
                Cursor   = Cursors.Default;
            }
        }
        public override void GenerarEXCEL(string titulo = "")
        {
            string pathFile = "", cuentaBancoEmpresa = "";
            string id = "", empleadoId, cedulaRNC, nombre, cuentaBancoEmpleado = "", formaPago = "E";
            double sueldoNeto = 0;
            int    I          = 2;
            string formula    = "";

            OfficeDriver.ExcelDriver objExcel = new OfficeDriver.ExcelDriver();
            DataTable DTCuenta = null, DTEmpleado = null;

            try
            {
                if (MyData == null)
                {
                    return;
                }
                if (MyData.Rows.Count <= 0)
                {
                    return;
                }

                Cursor = Cursors.WaitCursor;

                objExcel.isOpenOffice = objUtil.IsOpenOfficeIntalled();

                if (objExcel.isOpenOffice == false && objUtil.IsMSExcelIntalled() == false)
                {
                    throw new Exception("MS EXCEL U OPEN OFFICE CAL NO INSTALLED");
                }


                //Buscamos la Cuenta Bancaria Para Pago de Nomina o Transferencia Bancaria
                objDB.LimpiarFiltros();
                objDB.AddFiltroIgualA("Empresa_Id", empresaID.ToString());
                objDB.AddFiltroIgualA("EsActivo", "1");
                objDB.AddFiltroIgualA("EsNomina", "1");
                DTCuenta = objDB.GetAll("TBANCOS_CUENTAS_BANCARIAS", 1, objDB.Filtros);
                if (DTCuenta.Rows.Count > 0)
                {
                    cuentaBancoEmpresa = objUtil.GetAsString("Codigo_Completo", DTCuenta.Rows[0]);
                }

                if (cuentaBancoEmpresa.Trim() == "")
                {
                    Cursor = Cursors.Default;
                    objUtil.MostrarMensajeError("No se ha Definido Cuenta Bancaria Empresa Para el Pago de Nomina");
                    return;
                }


                //Establecemos el Id de la Nomina
                id = "Nomina_" + nominaId.ToString() + "_" + empresaID.ToString();

                pathFile = GetFolderDocGenerados("Nomina") + @"\" + id + ".xls";
                if (File.Exists(pathFile))
                {
                    File.Delete(pathFile);
                }

                //objExcel.create(pathFile, true);
                objExcel.OpenWorkBook("");
                objExcel.SetCellValue("A1", "RNC");
                objExcel.SetCellValue("B1", "CUENTA ORIGEN");
                objExcel.SetCellValue("C1", "CUENTA DESTINO");
                objExcel.SetCellValue("D1", "MONTO A PAGAR");
                objExcel.SetCellValue("E1", "REGISTRO ID");
                objExcel.SetCellValue("F1", "NOMBRE");
                objExcel.SetCellValue("G1", "FORMA PAGO");


                formula = "Sum(D2:D";

                foreach (DataRow item in MyData.Rows)
                {
                    this.Cursor = Cursors.WaitCursor;

                    empleadoId          = objUtil.GetAsString("Empleado_Id", item, "0");
                    cedulaRNC           = objUtil.GetAsString("CedulaRNC", item);
                    nombre              = objUtil.GetAsString("Nombre", item);
                    sueldoNeto          = objUtil.GetAsDouble("Monto_APagar", item, 0);
                    cuentaBancoEmpleado = objUtil.GetAsString("Cuenta_Banco_Destino", item, "");
                    formaPago           = objUtil.GetAsString("Forma_Pago", item, "CHK");

                    if (cuentaBancoEmpleado.Trim() == "")
                    {
                        //Buscamos la Cuenta de Banco de Dicho Empleado
                        DTEmpleado = objDB.GetById("TRRHH_EMPLEADOS", empleadoId, "Empleado_Id");
                        if (DTEmpleado.Rows.Count > 0)
                        {
                            cuentaBancoEmpleado = objUtil.GetAsString("Cuenta_Banco_No", DTEmpleado.Rows[0]);
                        }
                    }

                    objExcel.SetCellValue("A" + I.ToString(), EMPRESA_RNC);
                    objExcel.SetCellValue("B" + I.ToString(), cuentaBancoEmpresa);
                    objExcel.SetCellValue("C" + I.ToString(), cuentaBancoEmpleado);
                    objExcel.SetCellValue("D" + I.ToString(), sueldoNeto);
                    objExcel.SetCellValue("E" + I.ToString(), I - 1);
                    objExcel.SetCellValue("F" + I.ToString(), nombre);
                    objExcel.SetCellValue("G" + I.ToString(), formaPago);


                    I++;
                    this.Cursor = Cursors.Default;
                }
                formula += (I - 1).ToString() + ")";


                objExcel.SetCellFormula("D" + I.ToString(), formula);
                objExcel.Autofit();
                objExcel.SaveAS(pathFile);
                objExcel.ShowBook();

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
                //objExcel.CloseBook();
            }
        }
Esempio n. 3
0
        private void btnBuscarArchivo_Click(object sender, EventArgs e)
        {
            string nombreArchivo = "";
            string nombre = "", codigo = "", valor = "", marca = "", categoria = "";
            double cantidad = 0, costo = 0, precioRegular = 0, precioMinimo = 0, tasaItbis = 0;
            int    I = 2, conteo = 0;

            OfficeDriver.ExcelDriver excel = new OfficeDriver.ExcelDriver();
            bool resultado = true, esInventario = false;

            try
            {
                btnGrabar.Enabled = false;

                if (temporalID.Trim() == "")
                {
                    temporalID = objUtil.GetTemporalID();
                }
                else
                {
                    objDB.LimpiarDetalleTemporal("TTEMPORAL_CLASIFICADOR_PRODUCTOS", temporalID);
                }

                DataGridDetalle.DataSource = null;

                if (opFD.ShowDialog() == DialogResult.OK)
                {
                    Cursor = Cursors.WaitCursor;

                    nombreArchivo         = opFD.FileName;
                    txtNombreArchivo.Text = nombreArchivo;

                    if (cboCargarCon.Text == "MS OFFICE EXCEL")
                    {
                        excel.isOpenOffice = false;
                    }
                    else
                    {
                        excel.isOpenOffice = true;
                    }

                    excel.OpenWorkBook(nombreArchivo);

                    while (resultado)
                    {
                        Cursor = Cursors.WaitCursor;

                        nombre    = excel.GetCellValue("A" + I.ToString()).ToString();
                        codigo    = excel.GetCellValue("B" + I.ToString()).ToString();
                        marca     = excel.GetCellValue("C" + I.ToString()).ToString();
                        categoria = excel.GetCellValue("D" + I.ToString()).ToString();

                        valor    = excel.GetCellValue("E" + I.ToString()).ToString();
                        cantidad = objUtil.ConvertirANumero(valor);

                        valor = excel.GetCellValue("F" + I.ToString()).ToString();
                        costo = objUtil.ConvertirANumero(valor);

                        valor         = excel.GetCellValue("G" + I.ToString()).ToString();
                        precioRegular = objUtil.ConvertirANumero(valor);

                        valor        = excel.GetCellValue("H" + I.ToString()).ToString();
                        precioMinimo = objUtil.ConvertirANumero(valor);

                        valor = excel.GetCellValue("I" + I.ToString()).ToString().ToUpper();
                        if (valor == "1" || valor == "SI" || valor == "S" || valor == "YES" || valor == "Y")
                        {
                            esInventario = false;
                        }
                        else
                        {
                            esInventario = true;
                        }

                        valor     = excel.GetCellValue("J" + I.ToString()).ToString().ToUpper();
                        tasaItbis = objUtil.ConvertirANumero(valor);


                        if (nombre.Trim() == "")
                        {
                            resultado = false;
                            break;
                        }

                        //procedemos a insertar el detalle
                        if (marca.Trim() == "")
                        {
                            marca = "NO MARCA";
                        }
                        if (categoria.Trim() == "")
                        {
                            categoria = "NO CATEGORIA";
                        }

                        codigo = codigo.Replace(" ", "").Trim();
                        SetValorEncabezado("Nombre_Corto", nombre);
                        SetValorEncabezado("Descripcion", nombre);
                        SetValorEncabezado("Codigo_Barra", codigo);
                        SetValorEncabezado("Marca", marca);
                        SetValorEncabezado("Categoria", categoria);
                        SetValorEncabezado("Costo_Ultima_Compra", costo);
                        SetValorEncabezado("EnExistencia", cantidad);
                        SetValorEncabezado("Precio_Minimo", precioMinimo);
                        SetValorEncabezado("Precio_Regular", precioRegular);
                        SetValorEncabezado("EsInventario", esInventario);
                        SetValorEncabezado("Tasa_Itbis", tasaItbis);

                        objDB.Insertar("TTEMPORAL_CLASIFICADOR_PRODUCTOS", "", DSDatos.Tables[0], 0, CamposAExcluirEnc);

                        I++;
                        nombre = "";
                        Cursor = Cursors.Default;
                    }

                    excel.CloseBook();

                    objDB.LimpiarFiltros();
                    objDB.AddFiltroIgualA("IdentificadorTemp", temporalID);
                    objDB.AddFiltroOrderBY("Unico");
                    DTDetalle = objDB.GetAll("TTEMPORAL_CLASIFICADOR_PRODUCTOS", -1, objDB.Filtros);
                    DataGridDetalle.AutoGenerateColumns = false;
                    DataGridDetalle.DataSource          = DTDetalle.DefaultView;
                    conteo = DTDetalle.Rows.Count;

                    btnGrabar.Enabled = (DTDetalle.Rows.Count > 0);
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
                excel  = null;
            }
        }
        public override void GenerarEXCEL(string titulo = "")
        {
            DataRow  fila0;
            string   pathFile      = "";
            string   pathPlantilla = "";
            string   cedulaRNC     = "";
            string   periodo       = "";
            string   ncf           = "";
            DateTime fecha         = DateTime.Now;
            string   feComprobante = "";
            string   tipoAnulacion;
            int      lineaNo = 12;


            OfficeDriver.ExcelDriver objExcel = new OfficeDriver.ExcelDriver();

            try
            {
                if (MyData == null)
                {
                    return;
                }
                if (!objUtil.IsMSExcelIntalled())
                {
                    throw new Exception("MICROSOFT EXCEL NO ESTA INSTALADO...");
                }

                Cursor = Cursors.WaitCursor;
                objExcel.isOpenOffice = false;

                //Buscamos la Plantilla de excel
                pathPlantilla = System.Environment.CurrentDirectory + @"\Files\plantilla608.xls";
                if (!File.Exists(pathPlantilla))
                {
                    pathPlantilla = GetFolderDocGenerados("DGII") + @"\plantilla608.xls";
                }

                if (File.Exists(pathPlantilla))
                {
                    pathFile = GetFolderDocGenerados("DGII") + @"\temp_plantilla608.xls";
                    if (File.Exists(pathFile))
                    {
                        File.Delete(pathFile);
                    }

                    File.Copy(pathPlantilla, pathFile);
                }
                else
                {
                    objUtil.MostrarMensajeError("NO EXISTE PALNTILLA608.xls");
                    Cursor = Cursors.Default;
                    return;
                }

                tsProgressBar.Value   = 0;
                tsProgressBar.Maximum = MyData.Rows.Count + 1;
                tsProgressBar.Width   = 350;
                tsProgressBar.Step    = 1;
                tsProgressBar.Visible = true;

                fila0     = MyData.Rows[0];
                cedulaRNC = objUtil.GetAsString("EmpresaRNC", fila0).Replace("-", "");
                periodo   = objUtil.GetAsString("Periodo", fila0);

                //ABRIMOS EL ARCHIVO
                objExcel.OpenWorkBook(pathFile);

                objExcel.SetCellValue("C5", cedulaRNC);
                objExcel.SetCellValue("C6", periodo);
                objExcel.SetCellValue("C7", conteo);


                tsProgressBar.PerformStep();

                //EJECUTAMOS LA MACRO
                objExcel.RunMacro("'Formato608.cmdDataEntry_Click'");

                foreach (DataRow item in MyData.Rows)
                {
                    Cursor = Cursors.WaitCursor;

                    ncf           = objUtil.GetAsString("NCF", item);
                    fecha         = objUtil.GetAsDate("Fecha_Comprobante", item);
                    feComprobante = objUtil.DateToInt(fecha).ToString();

                    tipoAnulacion = objUtil.GetAsString("Tipo_Anulacion", item);

                    objExcel.SetCellValue("B" + lineaNo.ToString(), ncf);
                    objExcel.SetCellValue("D" + lineaNo.ToString(), feComprobante);
                    objExcel.SetCellValue("E" + lineaNo.ToString(), tipoAnulacion);

                    tsProgressBar.PerformStep();

                    lineaNo++;

                    Cursor = Cursors.Default;
                }

                objExcel.ShowBook();
            }
            catch (Exception ex)
            {
                if (objExcel != null)
                {
                    objExcel.CloseBook();
                }
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                objExcel = null;
                Cursor   = Cursors.Default;
            }
        }
        private void btnBuscarArchivo_Click(object sender, EventArgs e)
        {
            string nombreArchivo = "";
            string cuentaContable = "", descripcion = "", valor = "";
            int    oficinaId = 0, I = 2, conteo = 0;
            double saldo = 0, diferencia = 0;

            OfficeDriver.ExcelDriver excel = new OfficeDriver.ExcelDriver();
            bool resultado                 = true;

            try
            {
                btnGrabar.Enabled = false;

                if (temporalID.Trim() == "")
                {
                    temporalID = objUtil.GetTemporalID();
                }
                else
                {
                    objDB.LimpiarDetalleTemporal("TTEMPORAL_CONTA_CATALOGO", temporalID);
                }

                DataGridDetalle.DataSource = null;

                if (opFD.ShowDialog() == DialogResult.OK)
                {
                    Cursor = Cursors.WaitCursor;

                    nombreArchivo         = opFD.FileName;
                    txtNombreArchivo.Text = nombreArchivo;
                    Refresh();

                    if (cboCargarCon.Text == "MS OFFICE EXCEL")
                    {
                        excel.isOpenOffice = false;
                    }
                    else
                    {
                        excel.isOpenOffice = true;
                    }

                    excel.OpenWorkBook(nombreArchivo);

                    while (resultado)
                    {
                        Cursor = Cursors.WaitCursor;

                        cuentaContable = excel.GetCellValue("A" + I.ToString()).ToString();
                        descripcion    = excel.GetCellValue("B" + I.ToString()).ToString();

                        valor = excel.GetCellValue("C" + I.ToString()).ToString();
                        int.TryParse(valor, out oficinaId);

                        valor = excel.GetCellValue("D" + I.ToString()).ToString();
                        saldo = objUtil.ConvertirANumero(valor);

                        if (cuentaContable.Trim() == "")
                        {
                            resultado = false;
                            break;
                        }

                        //procedemos a insertar el detalle
                        cuentaContable = cuentaContable.Replace(" ", "").Trim();
                        SetValorEncabezado("Cuenta_Contable", cuentaContable);
                        SetValorEncabezado("Empresa_Id", EMPRESA_ID);
                        SetValorEncabezado("Descripcion", descripcion);
                        SetValorEncabezado("Oficina_Id", oficinaId);
                        SetValorEncabezado("Saldo_Actual", saldo);
                        SetValorEncabezado("Adicionado_Por", nombreUsuario);
                        SetValorEncabezado("IdentificadorTemp", temporalID);

                        objDB.Insertar("TTEMPORAL_CONTA_CATALOGO", "", DSDatos.Tables[0], 0, CamposAExcluirEnc);

                        I++;
                        cuentaContable = "";
                        Cursor         = Cursors.Default;
                    }

                    excel.CloseBook();
                    excel = null;


                    objDB.LimpiarFiltros();
                    objDB.AddFiltroIgualA("IdentificadorTemp", temporalID);
                    objDB.AddFiltroOrderBY("Cuenta_Contable");
                    DTDetalle = objDB.GetAll("TTEMPORAL_CONTA_CATALOGO", -1, objDB.Filtros);
                    DataGridDetalle.AutoGenerateColumns = false;
                    DataGridDetalle.DataSource          = DTDetalle.DefaultView;
                    diferencia = GetSumDetalle("Saldo_Actual");
                    conteo     = DTDetalle.Rows.Count;

                    lblDiferencia.Text = "Cantidad Registro: " + conteo.ToString("N0") + "         Diferencia: " + diferencia.ToString("N2");

                    btnGrabar.Enabled = (DTDetalle.Rows.Count > 0 && diferencia == 0);
                }
            }
            catch (Exception ex)
            {
                objUtil.MostrarMensajeError(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
                excel  = null;
            }
        }