示例#1
0
 /// <summary>
 /// Reinicia los parámetros de búsqueda.
 /// </summary>
 private void ResetFactura()
 {
     _FactParaBuscar = new ITInvoice
     {
         SellerParty = new Party()
     };
 }
示例#2
0
        /// <summary>
        /// Busqueda: Actualiza los datos del modelo
        /// con los datos actuales de la vista.
        /// </summary>
        private void BindModelBusqueda()
        {
            _FactParaBuscar = new ITInvoice();

            // Chequear datos
            DateTime issueDate;

            if (!DateTime.TryParse(txFechaBusqueda.Text, out issueDate))
            {
                MessageBox.Show("Debe introducir una fecha correcta");
                txFechaBusqueda.Focus();
                return;
            }

            // Necesitamos indicar una fecha de factura, para que se pueda calcular el ejercicio y periodo
            // que son necesarios y obligatorios para realizar esta peticiones.
            _FactParaBuscar.IssueDate = Convert.ToDateTime(issueDate);

            // Si informamos el nombre del Acreedor, el resto de campos son obligatorios y se tienen que informar
            if (!string.IsNullOrEmpty(txNomBusqueda.Text))
            {
                _FactParaBuscar.BuyerParty = new Party() // El cliente
                {
                    PartyName = txNomBusqueda.Text
                };

                if (string.IsNullOrEmpty(txNifBusqueda.Text))
                {
                    MessageBox.Show("Si informa el nombre de un Acreedor, también tiene que indicar un NIF");
                    txNifBusqueda.Focus();
                    return;
                }
                else
                {
                    _FactParaBuscar.BuyerParty.TaxIdentificationNumber = txNifBusqueda.Text;
                }

                if (lbCountry.Text != "")
                {
                    _FactParaBuscar.CountryCode = lbCountry.Text;
                }

                if (string.IsNullOrEmpty(txFactBusqueda.Text))
                {
                    MessageBox.Show("Si informa el nombre de un Acreedor, también tiene que indicar la serie número de una factura");
                    txFactBusqueda.Focus();
                    return;
                }
                else
                {
                    _FactParaBuscar.InvoiceNumber = txFactBusqueda.Text;
                }
            }


            _PetOperIntraEnviadas.ITInvoice = _FactParaBuscar;
        }
示例#3
0
        private void MnViewXML_Click(object sender, EventArgs e)
        {
            // Generaremos el lote para poder dar de baja las facturas que se hayan seleccionado en el DataGrid.
            _LoteBajaOperIntracom = new ITInvoicesDeleteBatch();

            foreach (DataGridViewRow row in grdInvoices.SelectedRows)
            {
                _LoteBajaOperIntracom.Titular = _Titular;

                ITInvoice _OperIntracomBaja         = new ITInvoice();
                RegistroRCLRDetOperIntracom _RegWrk = new RegistroRCLRDetOperIntracom();

                _RegWrk = (RegistroRCLRDetOperIntracom)row.Cells[5].Value;

                // Sólo daremos de baja aquellas facturas cuyo estado sean correctas, que tras realizar varias pruebas,
                // las anuladas también las devuelve y al seleccionarlas se puede producir un error.
                if (_RegWrk.EstadoFactura.EstadoRegistro == "Correcta")
                {
                    _OperIntracomBaja.BuyerParty = new Party
                    {
                        PartyName = _RegWrk.IDFactura.IDEmisorFactura.NombreRazon,
                        TaxIdentificationNumber = _RegWrk.IDFactura.IDEmisorFactura.NIF
                    };

                    if (_RegWrk.IDFactura.IDEmisorFactura.IDOtro != null)
                    {
                        _OperIntracomBaja.CountryCode = _RegWrk.IDFactura.IDEmisorFactura.IDOtro.CodigoPais;
                        _OperIntracomBaja.BuyerParty.TaxIdentificationNumber = _RegWrk.IDFactura.IDEmisorFactura.IDOtro.ID;
                    }

                    _OperIntracomBaja.IssueDate     = Convert.ToDateTime(_RegWrk.IDFactura.FechaExpedicionFacturaEmisor);
                    _OperIntracomBaja.InvoiceNumber = _RegWrk.IDFactura.NumSerieFacturaEmisor;

                    _LoteBajaOperIntracom.ITInvoices.Add(_OperIntracomBaja);
                }
            }

            try
            {
                string tmpath = Path.GetTempFileName();

                // Genera el archivo xml y lo guarda en la ruta facilitada comno parámetro
                _LoteBajaOperIntracom.GetXml(tmpath);

                FormXmlViewer frmXmlViewer = new FormXmlViewer
                {
                    Path = tmpath
                };

                frmXmlViewer.ShowDialog();
            }
            catch (Exception ex)
            {
                string _msgError = "Error: " + ex.Message;
                MessageBox.Show(_msgError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        // Función para tratar el registro de factura que se acaba de leer.
        private ITInvoice TratarOperIntracom(string[] _CamposReg, Party _Titular)
        {
            ITInvoice _FacturaActual = new ITInvoice();
            Party     _Emisor        = new Party();
            Party     _Receptor      = new Party();

            // Por las pruebas que hemos podido realizar, en el SoapUI, dependiendo de si se trata de una factura intracomunitaria emitida o recibida
            // el emisor de la misma será o el titular o el proveedor/acreedor que nos haya remitido la factura. En nuestro caso, al tratarse de facturas
            // recibidas, el emisor de la misma será el proveedor/acreedor. Procedemos a modificar el código para que se genere correctamente el lote.
            //
            // Informamos el Proveedor/Acreedor en nuestro caso.
            _Emisor.PartyName = (_CamposReg[3]).Trim();
            _Emisor.TaxIdentificationNumber = _CamposReg[4];

            if (!string.IsNullOrWhiteSpace(_CamposReg[5]))
            {
                _FacturaActual.CountryCode = _CamposReg[5];
            }
            _FacturaActual.BuyerParty = _Emisor;

            // Procedemos a tratar la factura actual.
            //El periodo impositivo no lo informamos, ya que se informará automáticamente a partir
            // de la fecha de la factura, según las pruebas que hemos realizado.
            _FacturaActual.InvoiceNumber = (_CamposReg[7]).Trim();
            _FacturaActual.IssueDate     = Convert.ToDateTime(_CamposReg[8]);

            // Informamos la contraparte de la factura, que en nuestro caso se trata del titular del lote.
            _Receptor = _Titular;
            _FacturaActual.SellerParty = _Receptor;

            // En el caso de que se trate de un cliente extranjero, habremos informado este campo, de manera que podremos indicar
            // el código de país correspondiente

            OperationType operationType;

            if (!Enum.TryParse <OperationType>(_CamposReg[11], out operationType))
            {
                MessageBox.Show($"El tipo de operación { _CamposReg[11]} es deconocido.");
            }

            _FacturaActual.OperationType = operationType;

            ClaveDeclarado claveDeclarado;

            if (!Enum.TryParse <ClaveDeclarado>(_CamposReg[12], out claveDeclarado))
            {
                MessageBox.Show($"La clave declarado {_CamposReg[12]} es desconocido.");
            }
            _FacturaActual.ClaveDeclarado = claveDeclarado;

            _FacturaActual.EstadoMiembro     = _CamposReg[13];
            _FacturaActual.DescripcionBienes = _CamposReg[14];
            _FacturaActual.DireccionOperador = _CamposReg[15];

            return(_FacturaActual);
        }
示例#5
0
        /// <summary>
        /// Reinicia la factura en curso.
        /// </summary>
        private void ResetFactura()
        {
            _FacturaEnCurso = new ITInvoice
            {
                //_FacturaEnCurso.BuyerParty = _Buyer; // El emisor de la factura
                BuyerParty  = new Party(),
                SellerParty = new Party() // El cliente
            };                            // factura

            ChangeCurrentInvoiceIndex(-1);
        }
示例#6
0
 private void grdFacturas_DoubleClick(object sender, EventArgs e)
 {
     if (grdInvoices.SelectedRows.Count > 0)
     {
         _FacturaEnCurso = (ITInvoice)grdInvoices.SelectedRows[0].Cells[6].Value;
         //_FacturaEnCurso.BuyerParty.TaxIdentificationNumber no contiene ningún valor
         ChangeCurrentInvoiceIndex(grdInvoices.SelectedRows[0].Index);
         BindViewFactura();
         BindViewTitular();
         BindViewAcreedor();
     }
 }
示例#7
0
        /// <summary>
        /// Crea lote de facturas recibidas.
        /// </summary>
        /// <returns>Lote de facturas recibidas de prueba.</returns>
        private static ITInvoicesBatch CrearLoteOperIntracom()
        {
            // Creamos al titular del lote.
            Party titular = new Party()
            {
                TaxIdentificationNumber =
                    "B12959755",
                PartyName = "IRENE SOLUTIONS SL"
            };

            // Lote de factura recibidas a enviar la AEAT al SII
            ITInvoicesBatch LoteOperIntracom = new ITInvoicesBatch();

            LoteOperIntracom.Titular           = titular;
            LoteOperIntracom.CommunicationType = CommunicationType.A0; // Alta de facturas:
            // utilizando el tipo de comunicación podemos modificar datos de facturas envíadas
            // anteriormente. En lugar de alta de facturas, podemos elegir modificación.


            Party comprador = titular; // El titular es el comprador en este caso

            // Ejemplo de una factura Intracomunitaria EMITIDA, en la que el titular y el 'buyer' son el mismo
            ITInvoice operIntracomPrimera = new ITInvoice();

            operIntracomPrimera.IssueDate = new DateTime(2017, 1, 15);// Fecha de emisión factura (Ejemplo raro, sujeta con nif extranjero)

            operIntracomPrimera.CountryCode = "DK";

            operIntracomPrimera.SellerParty = new Party() // Acreedor (Emisor factura)
            {
                TaxIdentificationNumber =
                    "DK12345678",
                PartyName = "CLIENTE EXTRANJERO LTD"
            };

            //
            // Según pruebas realizadas, parece ser que el 'BuyerParty' tiene que ser el mismo que el titular del libro, ya que sino indica un
            // error de que hay que indicar que se trata de un NIF-IVA (02).
            //
            operIntracomPrimera.BuyerParty = titular;      // Comprador

            operIntracomPrimera.InvoiceNumber = "OI00016"; // Número de factura

            operIntracomPrimera.OperationType  = OperationType.A;
            operIntracomPrimera.ClaveDeclarado = ClaveDeclarado.D;

            operIntracomPrimera.EstadoMiembro = "DK";

            operIntracomPrimera.DescripcionBienes = "Descripción de los bienes ...";
            operIntracomPrimera.DireccionOperador = "Dirección del operador ...";

            LoteOperIntracom.ITInvoices.Add(operIntracomPrimera); // Añado la factura al lote

            //
            // Ejemplo de una factura Intracomunitaria RECIBIDA, en la que el titular y el 'seller' son el mismo
            //
            ITInvoice operIntracomSegunda = new ITInvoice();

            operIntracomSegunda.IssueDate = new DateTime(2017, 1, 16);// Fecha de emisión factura (Ejemplo raro, sujeta con nif extranjero)

            operIntracomSegunda.CountryCode = "DK";

            operIntracomSegunda.BuyerParty = new Party() // Acreedor (Emisor factura)
            {
                TaxIdentificationNumber =
                    "DK12345678",
                PartyName = "CLIENTE EXTRANJERO LTD"
            };

            operIntracomSegunda.SellerParty = titular;     // Comprador

            operIntracomSegunda.InvoiceNumber = "OI00017"; // Número de factura

            operIntracomSegunda.OperationType  = OperationType.A;
            operIntracomSegunda.ClaveDeclarado = ClaveDeclarado.D;

            operIntracomSegunda.EstadoMiembro = "ES";

            operIntracomSegunda.DescripcionBienes = "Descripción de los bienes 2 ...";
            operIntracomSegunda.DireccionOperador = "Dirección del operador 2 ...";

            LoteOperIntracom.ITInvoices.Add(operIntracomSegunda); // Añado la factura al lote

            return(LoteOperIntracom);
        }
示例#8
0
        public void GenerarXMLIntracom(string _NombreFichero)
        {
            Intracom funcion        = new Intracom();
            string   _NomFicheroWrk = _NombreFichero;

            try
            {
                ITInvoicesBatch _LoteOperIntracom = new ITInvoicesBatch();
                ITInvoice       _OperIntracomAct  = new ITInvoice();
                Party           _Titular          = new Party();

                using (StreamReader _Lector = new StreamReader(_NomFicheroWrk))
                {
                    while (_Lector.Peek() > -1)
                    {
                        string _RegFichero = _Lector.ReadLine();
                        if (!String.IsNullOrEmpty(_RegFichero))
                        {
                            // Con creamos un Array con los distintos campos que contiene el registro separados por ";"
                            string[] _CamposReg = _RegFichero.Split(';');
                            string   _TipoReg   = _CamposReg[0];

                            switch (_TipoReg)
                            {
                            case "CABE":
                                _Titular = funcion.TratarRegCabecera(_CamposReg);
                                _LoteOperIntracom.Titular = _Titular;
                                string _TipoComunicacion = _CamposReg[3];
                                switch (_TipoComunicacion)
                                {
                                case "A0":
                                    _LoteOperIntracom.CommunicationType = CommunicationType.A0;
                                    break;

                                case "A1":
                                    _LoteOperIntracom.CommunicationType = CommunicationType.A1;
                                    break;

                                case "A4":
                                    _LoteOperIntracom.CommunicationType = CommunicationType.A4;
                                    break;
                                }
                                break;

                            case "FACT":
                                _OperIntracomAct = new ITInvoice();
                                _OperIntracomAct = funcion.TratarOperIntracom(_CamposReg, _Titular);
                                _LoteOperIntracom.ITInvoices.Add(_OperIntracomAct);
                                break;

                            case "FINI":
                                // Procedemos a generar el XML final.
                                DateTime _FechaActual  = DateTime.Today;    //Obtenemos la fecha actual sin la hora
                                string   nombrefichero = "SII_Intracom_" + _Titular.TaxIdentificationNumber + "_" + _FechaActual.ToString("yyyyMMdd") + ".XML";
                                string   XmlResult     = "C:/Temp/" + nombrefichero;
                                _LoteOperIntracom.GetXml(XmlResult);

                                string _msg = "Fichero XML generado: " + XmlResult;
                                MessageBox.Show(_msg, "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;

                            default:
                                string _msgAviso = "Tipo Registro incorrecto: " + _TipoReg;
                                MessageBox.Show(_msgAviso, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string _msgError = "Error: " + ex.Message;
                MessageBox.Show(_msgError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }