Implement Supplier AutoSupplierPayment. closes #100 #105
|
@ -0,0 +1,77 @@
|
|||
package org.hso.ecommerce.controller.cronjob;
|
||||
|
||||
import org.hso.ecommerce.action.booking.CreateBookingAction;
|
||||
import org.hso.ecommerce.entities.booking.Booking;
|
||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
|
||||
import org.hso.ecommerce.entities.booking.BookingReason;
|
||||
import org.hso.ecommerce.entities.supplier.Supplier;
|
||||
import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
|
||||
import org.hso.ecommerce.repos.booking.BookingRepository;
|
||||
import org.hso.ecommerce.repos.supplier.SupplierRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
@Component
|
||||
public class AutoSupplierPayment implements ICronjob {
|
||||
|
||||
@Autowired
|
||||
private SupplierRepository supplierRepository = null;
|
||||
|
||||
@Autowired
|
||||
private BookingAccountEntryRepository bookingAccountEntryRepository = null;
|
||||
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository = null;
|
||||
|
||||
@Override
|
||||
public Calendar nextExecution(Calendar reference) {
|
||||
if (reference.get(Calendar.HOUR_OF_DAY) >= 10) {
|
||||
reference.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
reference.set(Calendar.HOUR_OF_DAY, 10);
|
||||
reference.set(Calendar.MINUTE, 0);
|
||||
reference.set(Calendar.SECOND, 0);
|
||||
reference.set(Calendar.MILLISECOND, 0);
|
||||
return reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar previousExecution(Calendar reference) {
|
||||
if (reference.get(Calendar.HOUR_OF_DAY) < 10) {
|
||||
reference.add(Calendar.DAY_OF_MONTH, -1);
|
||||
}
|
||||
reference.set(Calendar.HOUR_OF_DAY, 10);
|
||||
reference.set(Calendar.MINUTE, 0);
|
||||
reference.set(Calendar.SECOND, 0);
|
||||
reference.set(Calendar.MILLISECOND, 0);
|
||||
return reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAt(Calendar time, CronjobController controller) {
|
||||
|
||||
for (Supplier supplier : supplierRepository.findAll()) {
|
||||
int debts = bookingAccountEntryRepository
|
||||
.getBySupplier(supplier.id)
|
||||
.map(entry -> entry.newSumCent).orElse(0);
|
||||
|
||||
if (debts > 0) {
|
||||
Booking booking = new CreateBookingAction(
|
||||
bookingAccountEntryRepository.getBySupplier(supplier.id).orElseGet(() -> BookingAccountEntry.newSupplier(supplier)),
|
||||
null,
|
||||
new BookingReason(supplier),
|
||||
debts
|
||||
).finish();
|
||||
|
||||
bookingRepository.save(booking);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Supplier Auto Payment";
|
||||
}
|
||||
}
|
|
@ -22,8 +22,6 @@ import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
|||
import org.hso.ecommerce.repos.supplier.ArticleOfferRepository;
|
||||
import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
|
||||
import org.hso.ecommerce.repos.supplier.SupplierRepository;
|
||||
import org.hso.ecommerce.repos.user.UserRepository;
|
||||
import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
||||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -236,14 +234,11 @@ class ScheduledCronjob {
|
|||
class CronjobController {
|
||||
private static final Logger log = LoggerFactory.getLogger(CronjobController.class);
|
||||
|
||||
private static final Map<String, ICronjob> cronjobs = getCronjobs();
|
||||
private Map<String, ICronjob> cronjobs;
|
||||
|
||||
@Autowired
|
||||
private final BackgroundJobRepository cronjobRepository = null;
|
||||
|
||||
@Autowired
|
||||
final SlotRepository slotRepository = null;
|
||||
|
||||
@Autowired
|
||||
final ArticleRepository articleRepository = null;
|
||||
|
||||
|
@ -272,14 +267,26 @@ class CronjobController {
|
|||
final SupplierOrderRepository supplierOrderRepository = null;
|
||||
|
||||
@Autowired
|
||||
final UserRepository userRepository = null;
|
||||
final Reorder reorderJob = null;
|
||||
|
||||
private static Map<String, ICronjob> getCronjobs() {
|
||||
@Autowired
|
||||
final DashboardCronjob dashboardCronjob = null;
|
||||
|
||||
@Autowired
|
||||
final AutoSupplierPayment autoSupplierPaymentJob = null;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
cronjobs = getCronjobs();
|
||||
}
|
||||
|
||||
private Map<String, ICronjob> getCronjobs() {
|
||||
HashMap<String, ICronjob> map = new HashMap<>();
|
||||
|
||||
// Register all existing cronjobs
|
||||
map.put(BackgroundJob.JOB_REORDER, new Reorder());
|
||||
map.put(BackgroundJob.JOB_DASHBOARD, new DashboardCronjob());
|
||||
map.put(BackgroundJob.JOB_REORDER, reorderJob);
|
||||
map.put(BackgroundJob.JOB_DASHBOARD, dashboardCronjob);
|
||||
map.put(BackgroundJob.JOB_SUPPLIER_AUTO_PAYMENT, autoSupplierPaymentJob);
|
||||
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@ package org.hso.ecommerce.controller.cronjob;
|
|||
import org.hso.ecommerce.action.warehouse.CalculateWarehouseStatsAction;
|
||||
import org.hso.ecommerce.entities.dashboard.DashboardSummary;
|
||||
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
||||
import org.hso.ecommerce.repos.user.UserRepository;
|
||||
import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
||||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
@ -13,6 +18,18 @@ import java.util.stream.Collectors;
|
|||
@Component
|
||||
public class DashboardCronjob implements ICronjob {
|
||||
|
||||
@Autowired
|
||||
private SlotRepository slotRepository = null;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository = null;
|
||||
|
||||
@Autowired
|
||||
private WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository = null;
|
||||
|
||||
@Autowired
|
||||
private CustomerOrderRepository customerOrderRepository = null;
|
||||
|
||||
@Override
|
||||
public Calendar nextExecution(Calendar reference) {
|
||||
reference.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
@ -40,19 +57,19 @@ public class DashboardCronjob implements ICronjob {
|
|||
|
||||
DashboardSummary dashboardSummary = new DashboardSummary();
|
||||
|
||||
List<WarehouseBookingPositionSlotEntry> entries = controller.slotRepository.findAll().stream().map(
|
||||
s -> controller.warehouseBookingPositionSlotEntryRepository
|
||||
List<WarehouseBookingPositionSlotEntry> entries = slotRepository.findAll().stream().map(
|
||||
s -> warehouseBookingPositionSlotEntryRepository
|
||||
.getBySlotNum(s.slotNum)
|
||||
.orElseGet(() -> WarehouseBookingPositionSlotEntry.empty(null, s))
|
||||
).collect(Collectors.toList());
|
||||
CalculateWarehouseStatsAction.WarehouseStats warehouseStats = new CalculateWarehouseStatsAction(entries).finish();
|
||||
CalculateWarehouseStatsAction.WarehouseStats warehouseStats = new CalculateWarehouseStatsAction(entries).finish();
|
||||
|
||||
dashboardSummary.created = new java.sql.Date(time.getTimeInMillis());
|
||||
dashboardSummary.todaysCustomersOrders = nullToZero(getSales(oneDayBefore, time, controller));
|
||||
dashboardSummary.todaysNewCustomers = nullToZero(getNewUsers(oneDayBefore, time, controller));
|
||||
dashboardSummary.todaysCustomersOrders = nullToZero(getSales(oneDayBefore, time));
|
||||
dashboardSummary.todaysNewCustomers = nullToZero(getNewUsers(oneDayBefore, time));
|
||||
dashboardSummary.todaysWarehouseCapacity = warehouseStats.efficiency;
|
||||
dashboardSummary.currentWarehouseCapacity = warehouseStats.ratioUsedSlots;
|
||||
dashboardSummary.todaysSalesCent = nullToZero(getTurnover(oneDayBefore, time, controller));
|
||||
dashboardSummary.todaysSalesCent = nullToZero(getTurnover(oneDayBefore, time));
|
||||
|
||||
controller.dashboardSummaryRepository.save(dashboardSummary);
|
||||
}
|
||||
|
@ -62,21 +79,18 @@ public class DashboardCronjob implements ICronjob {
|
|||
return "Dashboard refresh";
|
||||
}
|
||||
|
||||
private Integer getSales (Calendar begin, Calendar end, CronjobController controller)
|
||||
{
|
||||
return controller.customerOrderRepository.countOrdersInTimespan(
|
||||
private Integer getSales(Calendar begin, Calendar end) {
|
||||
return customerOrderRepository.countOrdersInTimespan(
|
||||
new Timestamp(begin.getTimeInMillis()), new Timestamp(end.getTimeInMillis()));
|
||||
}
|
||||
|
||||
private Integer getTurnover (Calendar begin, Calendar end, CronjobController controller)
|
||||
{
|
||||
return controller.customerOrderRepository.countTurnoverInTimespan(
|
||||
private Integer getTurnover(Calendar begin, Calendar end) {
|
||||
return customerOrderRepository.countTurnoverInTimespan(
|
||||
new Timestamp(begin.getTimeInMillis()), new Timestamp(end.getTimeInMillis()));
|
||||
}
|
||||
|
||||
private Integer getNewUsers (Calendar begin, Calendar end, CronjobController controller)
|
||||
{
|
||||
return controller.userRepository.countUsersInTimespan(
|
||||
private Integer getNewUsers(Calendar begin, Calendar end) {
|
||||
return userRepository.countUsersInTimespan(
|
||||
new Timestamp(begin.getTimeInMillis()), new Timestamp(end.getTimeInMillis()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package org.hso.ecommerce.controller.intern.accounting;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hso.ecommerce.entities.booking.Booking;
|
||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
|
||||
import org.hso.ecommerce.entities.booking.BookingReason;
|
||||
|
@ -13,6 +9,10 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class AccountingController {
|
||||
|
||||
|
@ -153,7 +153,9 @@ public class AccountingController {
|
|||
} else if (reason.customerPayment != null) {
|
||||
return "Bezahlung mit Kreditkarte " + reason.customerPayment.payment.creditCardNumber;
|
||||
} else if (reason.supplierOrder != null) {
|
||||
return "Lieferanten-Bestellung " + reason.supplierOrder.id;
|
||||
return "Lieferanten-Bestellung " + reason.supplierOrder.supplier.name;
|
||||
} else if (reason.supplierPayment != null) {
|
||||
return "Lieferanten-Zahlung " + reason.supplierPayment.name;
|
||||
} else {
|
||||
return "-";
|
||||
}
|
||||
|
@ -162,6 +164,10 @@ public class AccountingController {
|
|||
private String linkToReference(BookingReason reason) {
|
||||
if (reason.customerOrder != null) {
|
||||
return "/intern/customerOrders/" + reason.customerOrder.id;
|
||||
} else if (reason.supplierPayment != null) {
|
||||
return "/intern/suppliers/#q=" + reason.supplierPayment.id;
|
||||
} else if (reason.supplierOrder != null) {
|
||||
return "/intern/supplierOrders/#q=" + reason.supplierOrder.id;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.hso.ecommerce.entities.booking;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.hso.ecommerce.entities.supplier.Supplier;
|
||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
@ -28,6 +29,9 @@ public class BookingReason {
|
|||
@ManyToOne(optional = true)
|
||||
public SupplierOrder supplierOrder;
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
public Supplier supplierPayment;
|
||||
|
||||
// Default Constructor is needed for construction by ORM
|
||||
public BookingReason() {
|
||||
}
|
||||
|
@ -40,6 +44,10 @@ public class BookingReason {
|
|||
this.customerPayment = customerPayment;
|
||||
}
|
||||
|
||||
public BookingReason(Supplier supplierPayment) {
|
||||
this.supplierPayment = supplierPayment;
|
||||
}
|
||||
|
||||
public BookingReason(SupplierOrder supplierOrder) {
|
||||
this.supplierOrder = supplierOrder;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public class BackgroundJob {
|
|||
|
||||
public static final String JOB_DASHBOARD = "Dashboard";
|
||||
public static final String JOB_REORDER = "SupplierOrder";
|
||||
public static final String JOB_SUPPLIER_AUTO_PAYMENT = "SupplierAutoPayment";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
|
Reference in New Issue
Kleinigkeit zu Naming Conventions: Der Anfangsbuchstabe des Namens müsste klein sein.
fixed in
7fafd14715