diff --git a/prototype/scripts/addsupplierorders.sql b/prototype/scripts/addsupplierorders.sql
new file mode 100644
index 0000000..6c19af3
--- /dev/null
+++ b/prototype/scripts/addsupplierorders.sql
@@ -0,0 +1,3 @@
+
+INSERT INTO supplier_orders ("created", "delivered", "number_of_units", "price_per_unit_net_cent", "total_price_net", "ordered_id", "supplier_id")
+VALUES ('0', '0', '42', '42', '42', '1', '1');
diff --git a/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java b/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java
new file mode 100644
index 0000000..9bc413d
--- /dev/null
+++ b/prototype/src/main/java/org/hso/ecommerce/action/warehouse/StoreSupplierOrderAction.java
@@ -0,0 +1,7 @@
+package org.hso.ecommerce.action.warehouse;
+
+public class StoreSupplierOrderAction {
+
+ //TODO add delivery date and warehouse booking
+
+}
diff --git a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java
index bb0b5d6..b43478a 100644
--- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java
@@ -100,35 +100,6 @@ public class RequestController {
return "intern/customerOrders/id";
}
- @GetMapping("/intern/suppliers/")
- public String internSuppliers() {
- return "intern/suppliers/index";
- }
-
- @GetMapping("/intern/suppliers/{id}")
- public String internSuppliersId() {
- return "intern/suppliers/id";
- }
-
- @GetMapping("/intern/supplierOrders/")
- public String internSupplierOrders() {
- return "intern/supplierOrders/index";
- }
-
- @GetMapping("/intern/supplierOrders/{id}")
- public String internSupplierOrdersId() {
- return "intern/supplierOrders/id";
- }
-
- /*
-
- @GetMapping("/intern/suppliersOffers")
- public String internSuppliersOffers() {
- return "intern/offeredArticles/index";
- }
- */
-
-
@GetMapping("/intern/accounting/")
public String accounting() {
return "intern/accounting/index";
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java
index e011f71..e799210 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java
@@ -62,16 +62,12 @@ public class InternArticleController {
@GetMapping("/{id}")
public String internListedArticlesId(Model model, @PathVariable String id) {
-
int articleid = Integer.parseInt(id);
-
UImodelArticle total = new UImodelArticle();
-
total.addArticle(articleRepository.findArticleById(articleid),
warehouseEntryRepository.getArticleStock(articleid).orElse(0));
model.addAttribute("ArticleID", total);
-
return "intern/listedArticles/id";
}
@@ -80,7 +76,7 @@ public class InternArticleController {
@RequestParam(value = "title", required = true) String title,
@RequestParam(value = "description", required = true) String description,
@RequestParam(value = "units-per-slot", required = true) String warehouseUnitsPerSlot,
- @RequestParam(value = "price_netto", required = true) String pricenetto,
+ @RequestParam(value = "priceNet", required = true) String pricenetto,
@RequestParam(value = "reorderMaxPrice", required = true) String reorderMaxPrice,
@RequestParam(value = "autobuy", required = true) Boolean shouldReorder,
@RequestParam(value = "categorie", required = true) String categories,
@@ -192,19 +188,12 @@ public class InternArticleController {
public static class UImodelArticles {
public String imgPath;
-
public String title;
-
public String price;
-
- public String price_netto;
-
+ public String priceNet;
public String categorie;
-
public int stock;
-
- public long offer_id;
-
+ public long offerID;
public long id;
void addListedArticle(Article article, int stock) {
@@ -213,7 +202,7 @@ public class InternArticleController {
this.imgPath = article.image.path;
}
this.title = article.title;
- this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
+ this.priceNet = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
StringBuilder result = new StringBuilder();
@@ -224,7 +213,7 @@ public class InternArticleController {
this.categorie = result.toString();
this.stock = stock;
- this.offer_id = article.related.id;
+ this.offerID = article.related.id;
this.id = article.id;
}
}
@@ -234,123 +223,31 @@ public class InternArticleController {
public String imgPath;
public String title;
public String price;
- public String price_netto;
+ public String priceNet;
public String reorderMaxPrice;
public String categorie;
public int stock;
- public long offer_id;
+ public long offerID;
public long id;
public boolean shouldReorder;
public String warehouseUnitsPerSlot;
public String description;
public int vatPercent;
- public String getImgPath() {
- return imgPath;
- }
-
- public void setImgPath(String imgPath) {
- this.imgPath = imgPath;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getPrice() {
- return price;
- }
-
- public void setPrice(String price) {
- this.price = price;
- }
-
- public int getVatPercent() {
- return vatPercent;
- }
-
- public String getPrice_netto() {
- return price_netto;
- }
-
- public void setPrice_netto(String price_netto) {
- this.price_netto = price_netto;
- }
-
- public String getReorderMaxPrice() {
- return reorderMaxPrice;
- }
-
- public void setReorderMaxPrice(String reorderMaxPrice) {
- this.reorderMaxPrice = reorderMaxPrice;
- }
-
public String getCategorie() {
return categorie;
}
- public void setCategorie(String categorie) {
- this.categorie = categorie;
- }
-
- public int getStock() {
- return stock;
- }
-
- public void setStock(int stock) {
- this.stock = stock;
- }
-
- public long getOffer_id() {
- return offer_id;
- }
-
- public void setOffer_id(long offer_id) {
- this.offer_id = offer_id;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public boolean isShouldReorder() {
- return shouldReorder;
- }
-
- public void setShouldReorder(boolean shouldReorder) {
- this.shouldReorder = shouldReorder;
- }
-
- public String getWarehouseUnitsPerSlot() {
- return warehouseUnitsPerSlot;
- }
-
- public void setWarehouseUnitsPerSlot(String warehouseUnitsPerSlot) {
- this.warehouseUnitsPerSlot = warehouseUnitsPerSlot;
- }
-
public String getDescription() {
return description;
}
- public void setDescription(String description) {
- this.description = description;
- }
-
void addArticle(Article article, int stock) {
if (article.image != null) {
this.imgPath = article.image.path;
}
this.title = article.title;
- this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
+ this.priceNet = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
StringBuilder result = new StringBuilder();
@@ -362,7 +259,7 @@ public class InternArticleController {
this.categorie = result.toString();
this.stock = stock;
- this.offer_id = article.related.id;
+ this.offerID = article.related.id;
this.id = article.id;
this.reorderMaxPrice = String.format("%.2f", ((float) article.reorderMaxPrice / 100));
this.shouldReorder = article.shouldReorder;
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java
index d6cefc0..8f8c1fc 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierIndexController.java
@@ -1,8 +1,165 @@
package org.hso.ecommerce.controller.intern.suppliers;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import org.hso.ecommerce.entities.booking.Booking;
+import org.hso.ecommerce.entities.booking.BookingAccountEntry;
+import org.hso.ecommerce.entities.supplier.Supplier;
+import org.hso.ecommerce.entities.supplier.SupplierOrder;
+import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
+import org.hso.ecommerce.repos.booking.BookingRepository;
+import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
+import org.hso.ecommerce.repos.supplier.SupplierRepository;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
@Controller
-//@RequestMapping("...")
+@RequestMapping("/intern/")
public class SupplierIndexController {
+
+ @Autowired
+ private final SupplierRepository supplierRepository = null;
+
+ @Autowired
+ private final SupplierOrderRepository supplierOrderRepository = null;
+
+ @Autowired
+ private final BookingAccountEntryRepository bookingAccountEntryRepository = null;
+
+ @Autowired
+ private final BookingRepository bookingRepository = null;
+
+ @GetMapping("suppliers")
+ public String listSuppliers(Model model) {
+
+ List totals = new ArrayList();
+
+ for (Supplier supplier : supplierRepository.findAll()) {
+ UImodelSuppliers tmp = new UImodelSuppliers(supplier.id, supplier.name);
+ totals.add(tmp);
+ }
+
+ model.addAttribute("suppliers", totals);
+ return "intern/suppliers/index";
+ }
+
+ @GetMapping("/suppliers/{id}")
+ public String supplierDetail(Model model, @PathVariable String id) {
+
+ long supplierId = Long.parseLong(id);
+
+ // add orders from supplier to UImodel
+ List orders = new ArrayList();
+ for (SupplierOrder supplierOrder : supplierOrderRepository.findOrderBySupplierID(supplierId)) {
+ orders.add(new UImodelSupplierDetailOrders(supplierOrder));
+ }
+
+ // get latest supplier booking
+ Optional supplierBooking = bookingAccountEntryRepository.getBySupplier(supplierId);
+
+ // get account balance
+ String supplierBalance = ((supplierBooking.isPresent())
+ ? String.format("%.2f", ((float) supplierBooking.get().newSumCent / 100))
+ : "0,00");
+
+ // add bookings from supplier to UImodel
+ List bookings = new ArrayList();
+ for (Booking booking : bookingRepository.getBySupplier(supplierId)) {
+ bookings.add(new UImodelSupplierDetailBookings(booking));
+ }
+
+ UImodelSupplierDetail total = new UImodelSupplierDetail(supplierRepository.findSupplierById(supplierId).name,
+ supplierBalance, orders, bookings);
+
+ model.addAttribute("SupplierDetail", total);
+
+ return "intern/suppliers/id";
+ }
+
+ public class UImodelSuppliers {
+ public long id;
+ public String name;
+
+ public UImodelSuppliers(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ }
+
+ public class UImodelSupplierDetail {
+
+ public String name;
+ public String balance;
+ public List orders;
+ public List bookings;
+
+ public UImodelSupplierDetail(String name, String balance, List orders,
+ List bookings) {
+ this.name = name;
+ this.balance = balance;
+ this.orders = orders;
+ this.bookings = bookings;
+ }
+
+ }
+
+ public class UImodelSupplierDetailOrders {
+ public long id;
+ public String dateOrder;
+ public String articleName;
+ public long articleId;
+ public String priceNet;
+ public String quantity;
+ public String priceTotal;
+ public boolean arrived;
+
+ public UImodelSupplierDetailOrders(SupplierOrder order) {
+ this.id = order.id;
+ this.articleName = order.ordered.title;
+ this.articleId = order.ordered.id;
+ this.priceNet = String.format("%.2f", ((float) order.pricePerUnitNetCent / 100));
+ this.quantity = String.valueOf(order.numberOfUnits);
+ this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
+
+ Date date = new Date();
+ date.setTime(order.created.getTime());
+ this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
+
+ if (order.delivered != null) {
+ arrived = true;
+ } else {
+ arrived = false;
+ }
+ }
+ }
+
+ public class UImodelSupplierDetailBookings {
+
+ public String dateBooking;
+ public String price;
+ public String srcName;
+ public String balance;
+ public String reason;
+ public long orderID;
+
+ public UImodelSupplierDetailBookings(Booking booking) {
+ Date date = new Date();
+ date.setTime(booking.reason.supplierOrder.created.getTime());
+ this.dateBooking = new SimpleDateFormat("dd.MM.yyyy").format(date);
+ this.price = String.format("%.2f", ((float) booking.amountCent / 100));
+ this.srcName = ((booking.source.isMainAccount) ? "Hauptkonto" : booking.source.supplierAccount.name);
+ this.balance = String.format("%.2f", ((float) booking.destination.newSumCent / 100));
+ this.reason = booking.reason.comment;
+ this.orderID = booking.reason.supplierOrder.id;
+ }
+ }
}
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java
index edc7bc2..979f967 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java
@@ -40,94 +40,22 @@ public class SupplierOfferController {
public class UImodelOfferedArticle {
- long offer_id;
- String title;
- String manufacturer;
- String articlenumber;
- String supplierName;
- String price;
- String ads;
- int listedArticleId;
- boolean offerIsListed; // true --> offered article is listed
-
- public long getOffer_id() {
- return offer_id;
- }
-
- public void setOffer_id(long offer_id) {
- this.offer_id = offer_id;
- }
-
- public boolean isOfferIsListed() {
- return offerIsListed;
- }
-
- public void setOfferIsListed(boolean offerIsListed) {
- this.offerIsListed = offerIsListed;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getManufacturer() {
- return manufacturer;
- }
-
- public void setManufacturer(String manufacturer) {
- this.manufacturer = manufacturer;
- }
-
- public String getArticlenumber() {
- return articlenumber;
- }
-
- public void setArticlenumber(String articlenumber) {
- this.articlenumber = articlenumber;
- }
-
- public String getSupplierName() {
- return supplierName;
- }
-
- public void setSupplierName(String supplierName) {
- this.supplierName = supplierName;
- }
-
- public String getPrice() {
- return price;
- }
-
- public void setPrice(String price) {
- this.price = price;
- }
-
- public String getAds() {
- return ads;
- }
-
- public void setAds(String ads) {
- this.ads = ads;
- }
-
- public int getListedArticleId() {
- return listedArticleId;
- }
-
- public void setListedArticleId(int listedArticleId) {
- this.listedArticleId = listedArticleId;
- }
+ public long offerId;
+ public String title;
+ public String manufacturer;
+ public String articleNumber;
+ public String supplierName;
+ public String price;
+ public String ads;
+ public int listedArticleId;
+ public boolean offerIsListed; // true --> offered article is listed
public void addData(ArticleOffer article, Optional listedArticleId) {
- this.offer_id = article.id;
+ this.offerId = article.id;
this.title = article.title;
this.manufacturer = article.manufacturer;
- this.articlenumber = article.articleNumber;
+ this.articleNumber = article.articleNumber;
this.supplierName = article.cheapestSupplier.name;
this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100));
this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein";
diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
index ef3acb4..1485c92 100644
--- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
+++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java
@@ -1,8 +1,89 @@
package org.hso.ecommerce.controller.intern.suppliers;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import org.hso.ecommerce.entities.supplier.SupplierOrder;
+import org.hso.ecommerce.repos.supplier.SupplierOrderRepository;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.view.RedirectView;
@Controller
-//@RequestMapping("...")
+@RequestMapping("/intern/")
public class SupplierOrderController {
+
+ @Autowired
+ private final SupplierOrderRepository supplierOrderRepository = null;
+
+ @GetMapping("supplierOrders")
+ public String listSuppliers(Model model) {
+
+ List totals = new ArrayList();
+
+ for (SupplierOrder orders : supplierOrderRepository.findAll()) {
+ totals.add(new UImodelSupplierOrder(orders));
+ }
+
+ model.addAttribute("orders", totals);
+
+ return "intern/supplierOrders/index";
+ }
+
+ @PostMapping("/supplierOrders/store/{id}")
+ public RedirectView storeOrder(@PathVariable(required = true) String id) {
+
+ long supplierOrderID = Long.parseLong(id);
+
+ Optional order = supplierOrderRepository.findById(supplierOrderID);
+
+ if (order.isPresent()) {
+ // TODO call action
+
+ System.out.println("Order is present\n");
+
+ }
+
+ return new RedirectView("../../supplierOrders/");
+ }
+
+ public class UImodelSupplierOrder {
+ public long id;
+ public String dateOrder;
+ public String supplierName;
+ public String articleName;
+ public long articleId;
+ public String priceNet;
+ public String quantity;
+ public String priceTotal;
+ public boolean arrived;
+
+ public UImodelSupplierOrder(SupplierOrder order) {
+ this.id = order.id;
+ this.supplierName = order.supplier.name;
+ this.articleName = order.ordered.title;
+ this.articleId = order.ordered.id;
+ this.priceNet = String.format("%.2f", ((float) order.pricePerUnitNetCent / 100));
+ this.quantity = String.valueOf(order.numberOfUnits);
+ this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
+
+ Date date = new Date();
+ date.setTime(order.created.getTime());
+ this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
+
+ if (order.delivered != null) {
+ arrived = true;
+ } else {
+ arrived = false;
+ }
+ }
+ }
}
diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java
index 454b3f3..fe01783 100644
--- a/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java
+++ b/prototype/src/main/java/org/hso/ecommerce/repos/booking/BookingRepository.java
@@ -1,12 +1,17 @@
package org.hso.ecommerce.repos.booking;
+import java.util.List;
+
import org.hso.ecommerce.entities.booking.Booking;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface BookingRepository extends JpaRepository {
+ // Return a list with all bookings entries, sorted by id
+ @Query(value = "SELECT * FROM bookings as b INNER JOIN booking_account_entries ON b.destination_id=booking_account_entries.id OR b.source_id=booking_account_entries.id WHERE booking_account_entries.supplier_account_id = :supplier ORDER BY b.id DESC", nativeQuery = true)
+ List getBySupplier(Long supplier);
+
}
-
-
diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java
index 9d15e02..06ad249 100644
--- a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java
+++ b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierOrderRepository.java
@@ -1,8 +1,11 @@
package org.hso.ecommerce.repos.supplier;
+import java.util.List;
+
import org.hso.ecommerce.entities.supplier.SupplierOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
@@ -11,4 +14,9 @@ public interface SupplierOrderRepository extends JpaRepository findOrderBySupplierID(@Param("supplierId") long supplierId);
+
+ @Query("SELECT a FROM SupplierOrder a")
+ List findAll();
}
diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierRepository.java
index 2b81659..14b3a75 100644
--- a/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierRepository.java
+++ b/prototype/src/main/java/org/hso/ecommerce/repos/supplier/SupplierRepository.java
@@ -1,10 +1,19 @@
package org.hso.ecommerce.repos.supplier;
+import java.util.List;
+
import org.hso.ecommerce.entities.supplier.Supplier;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface SupplierRepository extends JpaRepository {
-
-}
+
+ @Query("SELECT a FROM Supplier a")
+ List findAll();
+
+ @Query("SELECT a FROM Supplier a WHERE a.id = :supplierId")
+ Supplier findSupplierById(@Param("supplierId") long supplierId);
+}
\ No newline at end of file
diff --git a/prototype/src/main/resources/templates/intern/listedArticles/id.html b/prototype/src/main/resources/templates/intern/listedArticles/id.html
index e1cd1a7..f179778 100644
--- a/prototype/src/main/resources/templates/intern/listedArticles/id.html
+++ b/prototype/src/main/resources/templates/intern/listedArticles/id.html
@@ -29,9 +29,9 @@
-
+
-
+
Details
@@ -48,10 +48,11 @@