diff --git a/pom.xml b/pom.xml index 7595ca8..72bad53 100644 --- a/pom.xml +++ b/pom.xml @@ -318,6 +318,12 @@ org.springframework.security spring-security-messaging + + + org.webjars + bootstrap + 4.0.0-2 + diff --git a/src/main/java/org/datasurvey/service/MailService.java b/src/main/java/org/datasurvey/service/MailService.java index 13b50b3..525e75d 100644 --- a/src/main/java/org/datasurvey/service/MailService.java +++ b/src/main/java/org/datasurvey/service/MailService.java @@ -4,6 +4,7 @@ import java.nio.charset.StandardCharsets; import java.util.Locale; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; +import org.datasurvey.domain.Factura; import org.datasurvey.domain.User; import org.datasurvey.domain.UsuarioEncuesta; import org.datasurvey.domain.UsuarioExtra; @@ -33,6 +34,8 @@ public class MailService { private static final String CONTRASENNA = "contrasenna"; + private static final String FACTURA = "factura"; + private static final String BASE_URL = "baseUrl"; private final JHipsterProperties jHipsterProperties; @@ -128,6 +131,22 @@ public class MailService { sendEmail(user.getEmail(), subject, content, false, true); } + @Async + public void sendEmailFromTemplateFactura(User user, Factura factura, String templateName, String titleKey) { + if (user.getEmail() == null) { + log.debug("Email doesn't exist for user '{}'", user.getLogin()); + return; + } + Locale locale = Locale.forLanguageTag(user.getLangKey()); + Context context = new Context(locale); + context.setVariable(USER, user); + context.setVariable(FACTURA, factura); + context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl()); + String content = templateEngine.process(templateName, context); + String subject = messageSource.getMessage(titleKey, null, locale); + sendEmail(user.getEmail(), subject, content, false, true); + } + @Async public void sendActivationEmail(User user) { log.debug("Sending activation email to '{}'", user.getEmail()); @@ -203,4 +222,10 @@ public class MailService { "email.deleteColaborator.title" ); } + + @Async + public void sendReceiptUser(UsuarioExtra user, Factura factura) { + log.debug("Sending paypal receipt mail to '{}'", user.getUser().getEmail()); + sendEmailFromTemplateFactura(user.getUser(), factura, "mail/facturaPayPalEmail", "email.receipt.title"); + } } diff --git a/src/main/java/org/datasurvey/web/rest/FacturaResource.java b/src/main/java/org/datasurvey/web/rest/FacturaResource.java index 4a407dc..419318c 100644 --- a/src/main/java/org/datasurvey/web/rest/FacturaResource.java +++ b/src/main/java/org/datasurvey/web/rest/FacturaResource.java @@ -8,9 +8,12 @@ import java.util.Optional; import javax.validation.Valid; import javax.validation.constraints.NotNull; import org.datasurvey.domain.Factura; +import org.datasurvey.domain.UsuarioExtra; import org.datasurvey.repository.FacturaRepository; import org.datasurvey.service.FacturaQueryService; import org.datasurvey.service.FacturaService; +import org.datasurvey.service.MailService; +import org.datasurvey.service.UsuarioExtraService; import org.datasurvey.service.criteria.FacturaCriteria; import org.datasurvey.web.rest.errors.BadRequestAlertException; import org.slf4j.Logger; @@ -41,10 +44,22 @@ public class FacturaResource { private final FacturaQueryService facturaQueryService; - public FacturaResource(FacturaService facturaService, FacturaRepository facturaRepository, FacturaQueryService facturaQueryService) { + private final UsuarioExtraService userExtraService; + + private final MailService mailService; + + public FacturaResource( + FacturaService facturaService, + FacturaRepository facturaRepository, + FacturaQueryService facturaQueryService, + UsuarioExtraService userExtraService, + MailService mailService + ) { this.facturaService = facturaService; this.facturaRepository = facturaRepository; this.facturaQueryService = facturaQueryService; + this.userExtraService = userExtraService; + this.mailService = mailService; } /** @@ -60,11 +75,22 @@ public class FacturaResource { if (factura.getId() != null) { throw new BadRequestAlertException("A new factura cannot already have an ID", ENTITY_NAME, "idexists"); } + + Optional usuarioExtra = userExtraService.findOne(Long.parseLong(factura.getNombreUsuario())); + + factura.setNombreUsuario(usuarioExtra.get().getNombre()); + Factura result = facturaService.save(factura); + + mailService.sendReceiptUser(usuarioExtra.get(), factura); + return ResponseEntity .created(new URI("/api/facturas/" + result.getId())) .headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())) .body(result); + //retrieve yser + + //Enviar el correo } /** diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 9e05ac2..0d59fa4 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -64,3 +64,11 @@ email.deleteColaborator.title=Se le ha expulsado de una encuesta como colaborado email.deleteColaborator.greeting=¡Se le ha expulsado, {0}! email.deleteColaborator.text1=Fue expulsado de la encuesta {0}(#{1})" email.deleteColaborator.text2=Saludos, + + +email.receipt.title=Comprobante de pago +email.receipt.user={0} +email.receipt.fecha={0} +email.receipt.plantilla={0} +email.receipt.precio=${0} + diff --git a/src/main/resources/templates/mail/facturaPayPalEmail.html b/src/main/resources/templates/mail/facturaPayPalEmail.html new file mode 100644 index 0000000..2764744 --- /dev/null +++ b/src/main/resources/templates/mail/facturaPayPalEmail.html @@ -0,0 +1,262 @@ + + + + + + + + + + + JHipster activation + + + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + + + + + + + diff --git a/src/main/webapp/app/entities/factura/service/factura.service.ts b/src/main/webapp/app/entities/factura/service/factura.service.ts index 07ed844..2f236c9 100644 --- a/src/main/webapp/app/entities/factura/service/factura.service.ts +++ b/src/main/webapp/app/entities/factura/service/factura.service.ts @@ -19,6 +19,7 @@ export class FacturaService { constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {} create(factura: IFactura): Observable { + debugger; const copy = this.convertDateFromClient(factura); return this.http .post(this.resourceUrl, copy, { observe: 'response' }) diff --git a/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.html b/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.html index 612f793..ca7956a 100644 --- a/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.html +++ b/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.html @@ -17,13 +17,37 @@
-
+ + +

@@ -45,7 +69,10 @@
diff --git a/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.ts b/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.ts index f1c92ef..da767ba 100644 --- a/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.ts +++ b/src/main/webapp/app/entities/tienda/listar-tienda-plantilla/listar-tienda-plantilla.component.ts @@ -27,6 +27,7 @@ import { PaypalDialogComponent } from '../paypal-dialog/paypal-dialog.component' export class ListarTiendaPlantillaComponent implements OnInit { public searchString: string; public searchCategoria: string; + public searchPrecio: string; categorias?: ICategoria[]; account: Account | null = null; public searchEncuestaPublica: string; @@ -58,6 +59,7 @@ export class ListarTiendaPlantillaComponent implements OnInit { this.searchEncuestaPublica = ''; this.searchString = ''; this.searchCategoria = ''; + this.searchPrecio = ''; } ngOnInit(): void { diff --git a/src/main/webapp/app/entities/tienda/paypal-dialog/paypal-dialog.component.html b/src/main/webapp/app/entities/tienda/paypal-dialog/paypal-dialog.component.html index ffba176..400a2c7 100644 --- a/src/main/webapp/app/entities/tienda/paypal-dialog/paypal-dialog.component.html +++ b/src/main/webapp/app/entities/tienda/paypal-dialog/paypal-dialog.component.html @@ -9,7 +9,13 @@

Total: ${{ plantilla!.precio }}


- + +

La plantilla ha comprar no tiene costo alguno

+ + +