Пример #1
0
        /// <summary>
        /// Devuelve las facturas emitidas registradas
        /// por los clientes del titular
        /// del lote en el periodo indicado.
        /// </summary>
        /// <param name="period">Periodo en formato yyyy.MM.</param>
        /// <param name="titular">Titular de las facturas a recuperar.</param>
        /// <param name="proveedor">Proveedor del que recuperar las facturas.</param>
        /// <returns>Lista de facturas emitidas en el periodo.</returns>
        private static RespuestaConsultaLRFactInformadasProveedor GetByPeriodFR(string period, Party titular, Party proveedor)
        {
            APInvoicesQuery batchInvoiceQuery = new APInvoicesQuery()
            {
                Titular = titular
            };

            APInvoice templateInvoiceQuery = new APInvoice();

            templateInvoiceQuery.SellerParty = proveedor;

            string syear  = period.Substring(0, 4);
            string smonth = period.Substring(5, 2);

            int year  = Convert.ToInt32(syear);
            int month = Convert.ToInt32(smonth);

            DateTime date = new DateTime(year, month, 1);

            // Necesitamos indicar una fecha de factura, para que se pueda calcular el ejercicio y periodo
            // que son necesarios y obligatorios para realizar esta peticiones.
            templateInvoiceQuery.IssueDate = date;
            batchInvoiceQuery.APInvoice    = templateInvoiceQuery;

            string response = Wsd.GetFacturasRecibidasProveedor(batchInvoiceQuery);

            try
            {
                // Obtengo la respuesta de la consulta de facturas recibidas del archivo de respuesta de la AEAT.
                Envelope envelope = Envelope.FromXml(response);

                if (envelope.Body.RegistroRespuestaConsultaLRFactInformadasProveedor != null)
                {
                    return(envelope.Body.RegistroRespuestaConsultaLRFactInformadasProveedor);
                }

                SoapFault msgError = envelope.Body.RespuestaError;

                if (msgError != null)
                {
                    throw new Exception($"{msgError.FaultDescription}");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(null);
        }