Beispiel #1
0
        private void NotaDeCréditoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            notaDeCréditoToolStripMenuItem.Enabled = false;
            ListaNotaCredito Check = new ListaNotaCredito();

            Check.Show();
        }
        private void btn_Regresar_Click(object sender, EventArgs e)
        {
            this.Hide();
            ListaNotaCredito.operacionFactura = "Q";
            ListaNotaCredito Check = new ListaNotaCredito();

            Check.Show();
        }
        private void btn_SaveData_Click(object sender, EventArgs e)
        {
            btn_SaveData.Enabled = false;
            for (int i = 0; i < objListDocumentoDet.Count; i++)
            {
                objListDocumentoDet[i].DocumentoCabSerie = txt_Serie.Text;
                objListDocumentoDet[i].DocumentoCabNro   = txt_Numero.Text;
            }
            bool binsertar, bupdate, bdetalle = true;

            objDocumentoCab = new DocumentoCab();
            objDocumentoCab.DocumentoCabSerie           = txt_Serie.Text;
            objDocumentoCab.DocumentoCabNro             = txt_Numero.Text;
            objDocumentoCab.DocumentoCabClienteCod      = txt_codcliente.Text;
            objDocumentoCab.DocumentoCabFecha           = dpick_Fecha.Value;
            objDocumentoCab.DocumentoCabGlosa           = txt_GlosaCab.Text;
            objDocumentoCab.DocumentoCabIGV             = convertToDouble(txt_IGV.Text);
            objDocumentoCab.DocumentoCabTotalSinIGV     = convertToDouble(txt_ValorVenta.Text);
            objDocumentoCab.DocumentoCabTotal           = convertToDouble(txt_TotalPagar.Text);
            objDocumentoCab.DocumentoCabTipoDoc         = "07";
            objDocumentoCab.DocumentoCabTipoPago        = 1;
            objDocumentoCab.DocumentoCabTipoNotaCredito = cmb_Motivo.SelectedValue.ToString();
            objDocumentoCab.DocumentoCabTipoMoneda      = cmb_Moneda.SelectedValue.ToString();

            objDocumentoCab.DocumentoCabNroRef      = txt_NumeroBuscar.Text;
            objDocumentoCab.DocumentoCabSerieRef    = txt_SerieBuscar.Text;
            objDocumentoCab.DocumentoCabTipoDocRef  = "01";
            objDocumentoCab.DocumentoCabFechaDocRef = dpck_Fechadcto.Value;

            objDocumentoCab.DocumentoCabUsuAdd    = Ventas.UsuarioSession;
            objDocumentoCab.DocumentoCabFechaVcto = new DateTime(2000, 1, 1);
            if (Modificar == "G")
            {
                binsertar = objDocumento.insertarCabecera(objDocumentoCab, Ventas.UNIDADNEGOCIO);
                string msg = "";
                if (binsertar)
                {
                }
                else
                {
                    msg = "Hubo un problema al guardar";
                    MessageBox.Show(msg);
                    btn_SaveData.Enabled = true;

                    return;
                }
                for (int i = 0; i < objListDocumentoDet.Count; i++)
                {
                    bdetalle = objDocumento.insertDetalle(objListDocumentoDet[i]);
                    if (bdetalle == false)
                    {
                        MessageBox.Show("Error al guardar");
                        btn_SaveData.Enabled = true;
                        break;
                    }
                }
                if (bdetalle)
                {
                    MessageBox.Show("Nota de Crédito Guardada exitosamente");

                    btn_SaveData.Enabled = true;
                }
                DialogResult dialogResult = MessageBox.Show("Enviar a Sunat?", "ENVIAR DOCUMENTOS", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    objDocumentoElectronicoCab     = objDocumento.getDocumentoElectronicoCab(txt_Serie.Text, txt_Numero.Text, Ventas.UNIDADNEGOCIO);
                    objListDocumentoElectronicoDet = objDocumento.getDocumentoElectronicoDet(txt_Serie.Text, txt_Numero.Text, Ventas.UNIDADNEGOCIO);
                    String rutatext = objProceso.generarText(objDocumentoElectronicoCab, objListDocumentoElectronicoDet);
                    String mess     = objProceso.sendTxt(rutatext);

                    String   mensajeMostrar = "";
                    String[] array          = mess.Split('|');

                    List <String> objListaString = array.ToList();
                    if (objListaString.Count < 10)
                    {
                        mensajeMostrar = objListaString[1];
                        objDocumento.updateObservacionSunat(txt_Serie.Text, txt_Numero.Text, mensajeMostrar);
                        //objDocumento.updateEstadoAnulado(txt_Serie.Text, txt_Numero.Text);
                    }
                    else
                    {
                        mensajeMostrar = objListaString[9];
                        if (mensajeMostrar == "true")
                        {
                            mensajeMostrar = "Documento Enviado";
                            objDocumento.updateObservacionSunat(txt_Serie.Text, txt_Numero.Text, mensajeMostrar);
                            //objDocumento.updateEstadoAceptado(txt_Serie.Text, txt_Numero.Text);
                            objDocumento.updateEstadoEnviado(txt_Serie.Text, txt_Numero.Text);
                        }
                        else
                        {
                            objDocumento.updateObservacionSunat(txt_Serie.Text, txt_Numero.Text, mensajeMostrar);
                        }
                    }


                    MessageBox.Show(mensajeMostrar);
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }
            else
            {
                bupdate = objDocumento.updateCabecera(objDocumentoCab);
                string msg = "";
                if (bupdate)
                {
                }
                else
                {
                    msg = "Hubo un problema al guardar";
                    MessageBox.Show(msg);
                    btn_SaveData.Enabled = true;
                    return;
                }
                for (int i = 0; i < objListDocumentoDet.Count; i++)
                {
                    bupdate = objDocumento.updateDetalle(objListDocumentoDet[i]);
                    if (bupdate == false)
                    {
                        MessageBox.Show("Error al guardar");
                        btn_SaveData.Enabled = true;
                        break;
                    }
                }
                if (bupdate)
                {
                    MessageBox.Show("Nota de Crédito Guardada exitósamente");

                    btn_SaveData.Enabled = true;
                }

                btn_SaveData.Enabled = true;
            }
            // nuevoRegistro();
            this.Hide();
            ListaNotaCredito.operacionFactura = "Q";
            ListaNotaCredito Check = new ListaNotaCredito();

            Check.Show();
        }