/// <summary> /// Ejemplo de envío de un lote de facturas emitidas /// </summary> public void EnviarLoteFacturasEmitidas() { // Creamos un lote de factura recibidas ARInvoicesBatch LoteDeFacturasEmitidas = CreaLoteDeFacturasEmitidas(); // Creo el sobre SOAP con el objeto XML a enviar a la AEAT Envelope envelope = LoteDeFacturasEmitidas.GetEnvelope(); // Edito directamente el objeto XML FacturaExpedida facturaExpedida = envelope.Body.SuministroLRFacturasEmitidas.RegistroLRFacturasEmitidas[0].FacturaExpedida; facturaExpedida.Contraparte.IDOtro = new IDOtro { IDType = "06", CodigoPais = "US", ID = "NIF_EXTRANJERO" }; // Realizamos el envío del SOBRE a la AEAT Wsd.Send(envelope); // Muestro el xml de respuesta recibido de la AEAT en el web browser webBrw.Navigate(Settings.Current.InboxPath + LoteDeFacturasEmitidas.GetReceivedFileName()); }
// Función para tratar el registro de factura que se acaba de leer. private RegistroLRFacturasEmitidas TratarFactEmitida(string[] _CamposReg) { RegistroLRFacturasEmitidas _RegLRFactEmitWRK = new RegistroLRFacturasEmitidas(); // Informamos el periodo impositivo. PeriodoImpositivo _PeriodoWrk = new PeriodoImpositivo { Ejercicio = _CamposReg[1], Periodo = _CamposReg[2] }; _RegLRFactEmitWRK.PeriodoImpositivo = _PeriodoWrk; // Informamos el IDFactura. IDFactura _IDFactWrk = new IDFactura(); _IDFactWrk.IDEmisorFactura.NIF = _CamposReg[3]; _IDFactWrk.NumSerieFacturaEmisor = _CamposReg[4].Trim(); _IDFactWrk.FechaExpedicionFacturaEmisor = _CamposReg[5]; // En caso de que se trate de una factura de Asiento Resumen, hay que informar la última factura // que se incluye en este envío. if (!string.IsNullOrWhiteSpace(_CamposReg[14])) { _IDFactWrk.NumSerieFacturaEmisorResumenFin = _CamposReg[14]; } _RegLRFactEmitWRK.IDFactura = _IDFactWrk; // Procedemos a tratar la factura actual. FacturaExpedida _FacturaActual = new FacturaExpedida { TipoFactura = _CamposReg[6], ClaveRegimenEspecialOTrascendencia = _CamposReg[7], ImporteTotal = ((_CamposReg[8]).Trim()).Replace(',', '.') }; if (string.IsNullOrWhiteSpace(_CamposReg[9])) { _CamposReg[9] = "Hay que informar el concepto de la factura"; } _FacturaActual.DescripcionOperacion = _CamposReg[9].Trim(); // Informamos la contraparte, que cambiará dependiendo de si se trata de un cliente nacional o extranjero Contraparte _ClienteWrk = new Contraparte { NombreRazon = _CamposReg[10].Trim() }; if (string.IsNullOrWhiteSpace(_CamposReg[12])) { _ClienteWrk.NIF = _CamposReg[11]; } else { IDOtro _ClienteExtWrk = new IDOtro { CodigoPais = _CamposReg[12], IDType = _CamposReg[13], ID = _CamposReg[11] }; _ClienteWrk.IDOtro = _ClienteExtWrk; } _FacturaActual.Contraparte = _ClienteWrk; // Indicamos la fecha de operación, en el caso de que venga informada if (!string.IsNullOrWhiteSpace(_CamposReg[15])) { _FacturaActual.FechaOperacion = _CamposReg[15]; } // Procedemos a informar los campos en el caso de que se trate del envio de una factura rectificativa. if (!string.IsNullOrWhiteSpace(_CamposReg[16])) { _FacturaActual.TipoRectificativa = _CamposReg[16]; ImporteRectificacion _ImpRectifWrk = new ImporteRectificacion { BaseRectificada = ((_CamposReg[17]).Trim()).Replace(',', '.'), CuotaRectificada = ((_CamposReg[18]).Trim()).Replace(',', '.') }; _FacturaActual.ImporteRectificacion = _ImpRectifWrk; } // Procedemos a tratar el caso de que se trate del deslgose no Sujeto TipoDesglose tipoDesglose = new TipoDesglose(); DesgloseFactura desgloseFactura = new DesgloseFactura(); NoSujeta noSujeta = new NoSujeta(); if (!string.IsNullOrWhiteSpace(_CamposReg[19]) || !string.IsNullOrWhiteSpace(_CamposReg[20])) { if (!string.IsNullOrWhiteSpace(_CamposReg[19])) { noSujeta.ImportePorArticulos7_14_Otros = ((_CamposReg[19]).Trim()).Replace(',', '.'); } if (!string.IsNullOrWhiteSpace(_CamposReg[20])) { noSujeta.ImporteTAIReglasLocalizacion = ((_CamposReg[20]).Trim()).Replace(',', '.'); } desgloseFactura.NoSujeta = noSujeta; tipoDesglose.DesgloseFactura = desgloseFactura; _FacturaActual.TipoDesglose = tipoDesglose; } _RegLRFactEmitWRK.FacturaExpedida = _FacturaActual; return(_RegLRFactEmitWRK); }