Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5520 change request to 2865286637064977289828992900 29013707542054173492 clarification order validation and order details #1077

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dao/src/main/java/greencity/entity/order/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,10 @@ public class Order {

@Column(name = "sum_total_amount_without_discounts")
private Long sumTotalAmountWithoutDiscounts;

@Column(name = "ubs_courier_sum")
private Long ubsCourierSum;

@Column(name = "write_off_station_sum")
private Long writeOffStationSum;
}
14 changes: 13 additions & 1 deletion dao/src/main/java/greencity/enums/NotificationTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ public enum NotificationTrigger {
"Refund of bonuses after order cancellation"),
CUSTOM(
"Кастомна",
"Custom");
"Custom"),
ORDER_STATUS_CHANGED_FROM_FORMED_TO_BROUGHT_BY_HIMSELF(
"Статус замовлення змінений"
+ "з «Сформовано» на «Привезе сам»",
"Order status changed"
+ "from «Formed» to «Brought by himself»"),
HALF_PAID_ORDER_STATUS_BROUGHT_BY_HIMSELF(
"Статус не повністю оплаченого замовлення змінено на «Привезе сам»",
"Status of half paid order changed to «Brought by himself»"),
UNDERPAYMENT_WHEN_STATUS_DONE_OR_CANCELED(
"Статус не оплаченого"
+ "замовлення змінено на «Виконано» або «Скасовано»",
"Status of unpaid order changed to «Done» or «Canceled»");

private final String description;
private final String descriptionEng;
Expand Down
4 changes: 4 additions & 0 deletions dao/src/main/java/greencity/enums/NotificationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public enum NotificationType {
CANCELED_VIOLATION_THE_RULES_BY_THE_MANAGER,
CHANGED_IN_RULE_VIOLATION_STATUS,
LETS_STAY_CONNECTED,
TEST,
BONUSES_FROM_CANCELLED_ORDER,
ORDER_STATUS_CHANGED,
HALF_PAID_ORDER_WITH_STATUS_BROUGHT_BY_HIMSELF,
DONE_OR_CANCELED_UNPAID_ORDER,
CUSTOM;
}
5 changes: 4 additions & 1 deletion dao/src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,7 @@
<include file="db/changelog/logs/ch-insert-into-table-notification-templates-Safarov.xml"/>
<include file="db/changelog/logs/ch-add-table-notification-platforms-Safarov.xml"/>
<include file="db/changelog/logs/ch-insert-into-table-notification-platforms-Safarov.xml"/>
</databaseChangeLog>
<include file="db/changelog/logs/ch-insert-into-notification-templates-Kulbaba.xml"/>
<include file="db/changelog/logs/ch-insert-into-notification-platforms-Kulbaba.xml"/>
<include file="db/changelog/logs/ch-add-columns-to-order-table-Kulbaba.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="Kulbaba-3" author="Oleh Kulbaba">
<addColumn tableName="orders">
<column name="ubs_courier_sum" type="bigint" defaultValue="0"/>
<column name="write_off_station_sum" type="bigint" defaultValue='0'/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="Kulbaba-2" author="Oleh Kulbaba">
<insert tableName="notification_platforms">
<column name="body">Шановний клієнте! Ви підтвердили, що замовлення буде привезено Вами на Станцію приймання самостійно. Звертаємо Вашу увагу на необхідність здійснення розрахунків безпосередньо на Станції приймання. Дякуємо!</column>
<column name="body_eng">Dear client! You are confirmed the order will be brought by yourself to the Receiving station. We draw your attention to the necessity of making payment at the Receiving station. Thank you</column>
<column name="notification_receiver_type">EMAIL</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">11</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний клієнте! Ви підтвердили, що замовлення буде привезено Вами на Станцію приймання самостійно. Звертаємо Вашу увагу на необхідність здійснення розрахунків безпосередньо на Станції приймання. Дякуємо!</column>
<column name="body_eng">Dear client! You are confirmed the order will be brought by yourself to the Receiving station. We draw your attention to the necessity of making payment at the Receiving station. Thank you</column>
<column name="notification_receiver_type">SITE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">11</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний клієнте! Ви підтвердили, що замовлення буде привезено Вами на Станцію приймання самостійно. Звертаємо Вашу увагу на необхідність здійснення розрахунків безпосередньо на Станції приймання. Дякуємо!</column>
<column name="body_eng">Dear client! You are confirmed the order will be brought by yourself to the Receiving station. We draw your attention to the necessity of making payment at the Receiving station. Thank you</column>
<column name="notification_receiver_type">MOBILE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">11</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги на Станції приймання. Сума до сплати ${amountToPay}. грн</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services at the Receiving station. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">EMAIL</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">12</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги на Станції приймання. Сума до сплати ${amountToPay}. грн</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services at the Receiving station. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">SITE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">12</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги на Станції приймання. Сума до сплати ${amountToPay}. грн</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services at the Receiving station. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">MOBILE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">12</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги. Сума до сплати ${amountToPay}. грн.</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">EMAIL</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">13</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги. Сума до сплати ${amountToPay}. грн.</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">SITE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">13</column>
</insert>
<insert tableName="notification_platforms">
<column name="body">Шановний Клієнте! Інформуємо Вас про необхідність оплати за послуги. Сума до сплати ${amountToPay}. грн.</column>
<column name="body_eng">Dear client! We inform you about the necessity of paying for services. The sum is ${amountToPay}. UAH</column>
<column name="notification_receiver_type">MOBILE</column>
<column name="notification_status">ACTIVE</column>
<column name="notification_id">13</column>
</insert>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

<changeSet id="Kulbaba-1" author="Oleh Kulbaba">
<insert tableName="notification_templates">
<column name="notification_type">ORDER_STATUS_CHANGED</column>
<column name="trigger">ORDER_STATUS_CHANGED_FROM_FORMED_TO_BROUGHT_BY_HIMSELF</column>
<column name="time">IMMEDIATELY</column>
<column name="title">Статус замовлення: "Привезе сам"</column>
<column name="title_eng">Order status: "Brought by himself"</column>
<column name="notification_status">ACTIVE</column>
</insert>
<insert tableName="notification_templates">
<column name="notification_type">HALF_PAID_ORDER_WITH_STATUS_BROUGHT_BY_HIMSELF</column>
<column name="trigger">HALF_PAID_ORDER_STATUS_BROUGHT_BY_HIMSELF</column>
<column name="time">IMMEDIATELY</column>
<column name="title">Замовлення опалачене не повністю</column>
<column name="title_eng">Order is partially paid</column>
<column name="notification_status">ACTIVE</column>
</insert>
<insert tableName="notification_templates">
<column name="notification_type">DONE_OR_CANCELED_UNPAID_ORDER</column>
<column name="trigger">UNDERPAYMENT_WHEN_STATUS_DONE_OR_CANCELED</column>
<column name="time">IMMEDIATELY</column>
<column name="title">Неоплачене замовлення</column>
<column name="title_eng">Unpaid Order</column>
<column name="notification_status">ACTIVE</column>
</insert>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class UpdateOrderPageAdminDto {
private ExportDetailsDtoUpdate exportDetailsDto;
private UpdateOrderDetailDto orderDetailDto;
private List<UpdateResponsibleEmployeeDto> updateResponsibleEmployeeDto;
private Long writeOffStationSum;
private Long ubsCourierSum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public interface NotificationService {
*/
void notifyAllHalfPaidPackages();

/**
* Method sends messages by e-mail/notification that order is unpaid.
*
* @param order of {@link Order} Order which status was changed
* @author Oleh Kulbaba
*/
void notifyUnpaidOrder(Order order);

/**
* Method that returns page with notifications for user by UUID.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package greencity.service.notification;

import greencity.constant.OrderHistory;
import greencity.dto.notification.InactiveAccountDto;
import greencity.dto.notification.NotificationDto;
import greencity.dto.notification.NotificationShortDto;
import greencity.dto.pageble.PageableDto;
import greencity.dto.payment.PaymentResponseDto;
import greencity.entity.notifications.NotificationPlatform;
import greencity.entity.order.Certificate;
import greencity.enums.NotificationReceiverType;
import greencity.enums.NotificationType;
import greencity.enums.OrderPaymentStatus;
import greencity.enums.PaymentStatus;
import greencity.entity.order.*;
import greencity.enums.*;
import greencity.entity.notifications.NotificationParameter;
import greencity.entity.notifications.NotificationTemplate;
import greencity.entity.notifications.UserNotification;
import greencity.entity.order.Bag;
import greencity.entity.order.Order;
import greencity.entity.order.Payment;
import greencity.entity.user.User;
import greencity.entity.user.Violation;
import greencity.exceptions.NotFoundException;
Expand Down Expand Up @@ -174,6 +169,9 @@ public void notifyHalfPaidPackage(Order order) {
Integer certificatePointsUsed = order.getCertificates().stream()
.map(Certificate::getPoints).reduce(0, Integer::sum);

Long ubsCourierSum = order.getUbsCourierSum() == null ? 0 : order.getUbsCourierSum();
Long writeStationSum = order.getWriteOffStationSum() == null ? 0 : order.getWriteOffStationSum();

List<Bag> bags = bagRepository.findBagsByOrderId(order.getId());
Map<Integer, Integer> bagsAmount;
if (!order.getExportedQuantity().isEmpty()) {
Expand All @@ -187,13 +185,76 @@ public void notifyHalfPaidPackage(Order order) {
Integer price = bags.stream().map(bag -> bagsAmount.get(bag.getId()) * bag.getFullPrice())
.reduce(0, Integer::sum);

long amountToPay = price - (paidAmount + order.getPointsToUse() + certificatePointsUsed);
long amountToPay =
price - (paidAmount + order.getPointsToUse() + certificatePointsUsed) + ubsCourierSum + writeStationSum;

parameters.add(NotificationParameter.builder().key("amountToPay")
.value(String.format("%.2f", (double) amountToPay)).build());
parameters.add(NotificationParameter.builder().key("orderNumber")
.value(order.getId().toString()).build());
fillAndSendNotification(parameters, order, NotificationType.UNPAID_PACKAGE);
if (order.getOrderStatus() == OrderStatus.BROUGHT_IT_HIMSELF) {
fillAndSendNotification(parameters, order, NotificationType.HALF_PAID_ORDER_WITH_STATUS_BROUGHT_BY_HIMSELF);
} else if ((order.getOrderStatus() == OrderStatus.DONE || order.getOrderStatus() == OrderStatus.CANCELED)
&& order.getEvents().stream()
.map(Event::getEventName)
.filter(e -> e.equals(OrderHistory.ORDER_ADJUSTMENT) || e.equals(OrderHistory.ORDER_CONFIRMED)
|| e.equals(OrderHistory.ORDER_ON_THE_ROUTE) || e.equals(OrderHistory.ORDER_NOT_TAKEN_OUT))
.count() == 3) {
fillAndSendNotification(parameters, order, NotificationType.DONE_OR_CANCELED_UNPAID_ORDER);
} else {
fillAndSendNotification(parameters, order, NotificationType.UNPAID_PACKAGE);
}
}

@Override
public void notifyUnpaidOrder(Order order) {
Set<NotificationParameter> parameters = new HashSet<>();

Long totalPrice;
Long bonuses = order.getPointsToUse().longValue();
Long certificates =
order.getCertificates().stream().map(Certificate::getPoints).reduce(0, Integer::sum).longValue();
Long paidAmount = order.getPayment().stream()
.filter(payment -> payment.getPaymentStatus().equals(PaymentStatus.PAID))
.map(payment -> payment.getAmount() / 100)
.reduce(0L, Long::sum);

Long ubsCourierSum = order.getUbsCourierSum() == null ? 0 : order.getUbsCourierSum();
Long writeStationSum = order.getWriteOffStationSum() == null ? 0 : order.getWriteOffStationSum();

List<Bag> bags = bagRepository.findBagsByOrderId(order.getId());

if (!order.getExportedQuantity().isEmpty()) {
totalPrice = bags.stream()
.map(bag -> order.getExportedQuantity().get(bag.getId()) * bag.getFullPrice().longValue())
.reduce(0L, Long::sum);
} else if (!order.getConfirmedQuantity().isEmpty()) {
totalPrice = bags.stream()
.map(bag -> order.getConfirmedQuantity().get(bag.getId()) * bag.getFullPrice().longValue())
.reduce(0L, Long::sum);
} else {
totalPrice = bags.stream()
.map(bag -> order.getAmountOfBagsOrdered().get(bag.getId()) * bag.getFullPrice().longValue())
.reduce(0L, Long::sum);
}

Long amountToPay = totalPrice - paidAmount - bonuses - certificates + ubsCourierSum + writeStationSum;

parameters.add(NotificationParameter.builder().key("amountToPay")
.value(String.format("%.2f", (double) amountToPay)).build());
if (order.getOrderStatus() == OrderStatus.BROUGHT_IT_HIMSELF
&& order.getEvents().stream()
.map(Event::getEventName)
.noneMatch(e -> e.equals(OrderHistory.ORDER_ADJUSTMENT) || e.equals(OrderHistory.ORDER_CONFIRMED))) {
fillAndSendNotification(parameters, order, NotificationType.ORDER_STATUS_CHANGED);
} else if ((order.getOrderStatus() == OrderStatus.DONE || order.getOrderStatus() == OrderStatus.CANCELED)
&& order.getEvents().stream()
.map(Event::getEventName)
.filter(e -> e.equals(OrderHistory.ORDER_ADJUSTMENT) || e.equals(OrderHistory.ORDER_CONFIRMED)
|| e.equals(OrderHistory.ORDER_ON_THE_ROUTE) || e.equals(OrderHistory.ORDER_NOT_TAKEN_OUT))
.count() == 3) {
fillAndSendNotification(parameters, order, NotificationType.DONE_OR_CANCELED_UNPAID_ORDER);
}
}

/**
Expand Down
Loading