Apply some changes according to comments on the pullrequest
This commit is contained in:
parent
8fff0e2dca
commit
691916894f
|
@ -4,14 +4,13 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
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.repos.booking.BookingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
|
@ -169,7 +168,7 @@ public class AccountingController {
|
|||
}
|
||||
|
||||
@GetMapping("/intern/accounting/")
|
||||
public String accounting(HttpServletRequest request) {
|
||||
public String accounting(Model model) {
|
||||
List<Booking> bookings = bookingRepository.allBookingsReverseChronologically();
|
||||
List<TemplateBooking> templateBookings = new ArrayList<>();
|
||||
for (Booking booking : bookings) {
|
||||
|
@ -200,25 +199,25 @@ public class AccountingController {
|
|||
templateBookings.add(tb);
|
||||
}
|
||||
|
||||
request.setAttribute("bookings", templateBookings);
|
||||
model.addAttribute("bookings", templateBookings);
|
||||
return "intern/accounting/index";
|
||||
}
|
||||
|
||||
@GetMapping("/intern/accounting/vat")
|
||||
public String accountingVat(HttpServletRequest request) {
|
||||
public String accountingVat(Model model) {
|
||||
List<Booking> bookings = bookingRepository.vatBookingsReverseChronologically();
|
||||
ShortTemplateBookingResult result = buildShortTemplate(bookings, account -> account.isVATAccount);
|
||||
request.setAttribute("balance", result.balance);
|
||||
request.setAttribute("bookings", result.bookings);
|
||||
model.addAttribute("balance", result.balance);
|
||||
model.addAttribute("bookings", result.bookings);
|
||||
return "intern/accounting/vat";
|
||||
}
|
||||
|
||||
@GetMapping("/intern/accounting/main")
|
||||
public String accountingIntern(HttpServletRequest request) {
|
||||
public String accountingIntern(Model model) {
|
||||
List<Booking> bookings = bookingRepository.mainBookingsReverseChronologically();
|
||||
ShortTemplateBookingResult result = buildShortTemplate(bookings, account -> account.isMainAccount);
|
||||
request.setAttribute("balance", result.balance);
|
||||
request.setAttribute("bookings", result.bookings);
|
||||
model.addAttribute("balance", result.balance);
|
||||
model.addAttribute("bookings", result.bookings);
|
||||
return "intern/accounting/main";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hso.ecommerce.controller.intern.accounting;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hso.ecommerce.action.booking.CreateBookingAction;
|
||||
import org.hso.ecommerce.entities.booking.Booking;
|
||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
|
||||
|
@ -212,11 +214,15 @@ public class ManualAccountingController {
|
|||
} catch (NumberFormatException e) {
|
||||
throw new InvalidFormDataException("Die angegebene Kunden-Nr. ist ungültig.");
|
||||
}
|
||||
return bookingAccountEntryRepository.getByUser(userId).or(() -> {
|
||||
return userRepository.findById(userId).map((user) -> BookingAccountEntry.newUser(user));
|
||||
}).orElseThrow(() -> {
|
||||
return new InvalidFormDataException("Der Kunde Nr. " + userId + " konnte nicht gefunden werden.");
|
||||
});
|
||||
Optional<BookingAccountEntry> bookingAccount = bookingAccountEntryRepository.getByUser(userId);
|
||||
if (!bookingAccount.isPresent()) {
|
||||
bookingAccount = userRepository.findById(userId).map((user) -> BookingAccountEntry.newUser(user));
|
||||
}
|
||||
if (bookingAccount.isPresent()) {
|
||||
return bookingAccount.get();
|
||||
} else {
|
||||
throw new InvalidFormDataException("Der Kunde Nr. " + userId + " konnte nicht gefunden werden.");
|
||||
}
|
||||
} else if (account.equals("Sup")) {
|
||||
long supplierId;
|
||||
try {
|
||||
|
@ -224,12 +230,17 @@ public class ManualAccountingController {
|
|||
} catch (NumberFormatException e) {
|
||||
throw new InvalidFormDataException("Die angegebene Lieferanten-Nr. ist ungültig.");
|
||||
}
|
||||
return bookingAccountEntryRepository.getBySupplier(supplierId).or(() -> {
|
||||
return supplierRepository.findById(supplierId).map((sup) -> BookingAccountEntry.newSupplier(sup));
|
||||
}).orElseThrow(() -> {
|
||||
return new InvalidFormDataException(
|
||||
Optional<BookingAccountEntry> bookingAccount = bookingAccountEntryRepository.getBySupplier(supplierId);
|
||||
if (!bookingAccount.isPresent()) {
|
||||
bookingAccount = supplierRepository.findById(supplierId)
|
||||
.map((sup) -> BookingAccountEntry.newSupplier(sup));
|
||||
}
|
||||
if (bookingAccount.isPresent()) {
|
||||
return bookingAccount.get();
|
||||
} else {
|
||||
throw new InvalidFormDataException(
|
||||
"Der Lieferant Nr. " + supplierId + " konnte nicht gefunden werden.");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Invalid form value for an account: " + account);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class SupplierIndexController {
|
|||
private final BookingRepository bookingRepository = null;
|
||||
|
||||
@Autowired
|
||||
private AccountingController accountingController = null;
|
||||
private final AccountingController accountingController = null;
|
||||
|
||||
@GetMapping("suppliers")
|
||||
public String listSuppliers(Model model) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<form th:action="@{/intern/accounting/addManual}" th:object="${form_vals}" method="post" class="detailgrid">
|
||||
<div class="s">
|
||||
<label for="amount">Betrag</label>
|
||||
<input type="number" step="0.01" th:field="*{amount}" /> EUR
|
||||
<input type="number" step="0.01" id="amount" th:field="*{amount}" /> EUR
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
|
||||
|
|
Reference in New Issue