diff --git a/prototype/scripts/addarticles.sql b/prototype/scripts/addarticles.sql index f7e5f5b..b60497d 100644 --- a/prototype/scripts/addarticles.sql +++ b/prototype/scripts/addarticles.sql @@ -1,5 +1,5 @@ -INSERT INTO article_offers ("manufacturer", "article_number", "vat_percent", "should_be_advertised") -VALUES ("McDonalds", "1", 7, 1); +INSERT INTO article_offers ("manufacturer", "article_number", "price_per_unit_net", "title", "vat_percent", "should_be_advertised") +VALUES ("McDonalds", "1", 4242, "McPizza", 7, 1); INSERT INTO articles ("related_id", "shop_price_per_unit_net_cent", "warehouse_units_per_slot", "should_reorder", "reorder_max_price", "title", "description", "image_id") VALUES (1, 19.99, 10, 1, 15, "Huge Hamburger", "This huge Hamburger is awesome!", NULL); 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 0081c88..7a7e7fe 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 @@ -5,8 +5,10 @@ import java.util.List; import org.hso.ecommerce.entities.shop.Article; import org.hso.ecommerce.entities.shop.Category; +import org.hso.ecommerce.entities.supplier.ArticleOffer; import org.hso.ecommerce.repos.shop.ArticleRepository; import org.hso.ecommerce.repos.shop.CategoryRepository; +import org.hso.ecommerce.repos.shop.OffersRepository; import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,6 +28,9 @@ public class InternArticleController { @Autowired private final CategoryRepository categoryRepository = null; + @Autowired + private final OffersRepository offersRepository = null; + @GetMapping("/") public String internListedArticles(Model model) { @@ -57,39 +62,65 @@ public class InternArticleController { } @PostMapping("/{id}/saveChanges") - public RedirectView saveChanges( - @PathVariable int id, - @RequestParam("title") String title, - @RequestParam("description") String description, - @RequestParam("units-per-slot") String warehouseUnitsPerSlot, - @RequestParam("price_netto") String pricenetto, - @RequestParam("reorderMaxPrice") String reorderMaxPrice, - @RequestParam("autobuy") Boolean shouldReorder, - @RequestParam("categories") String categories) { + public RedirectView saveChanges(@PathVariable(required = true) int id, + @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 = "reorderMaxPrice", required = true) String reorderMaxPrice, + @RequestParam(value = "autobuy", required = true) Boolean shouldReorder, + @RequestParam(value = "categories", required = true) String categories) { - Article oldArticle = articleRepository.findArticleById(id); + Article tmpArticle = articleRepository.findArticleById(id); // get the old article // TODO img String[] separatedCategories = categories.split("\n"); - oldArticle.categories.clear(); + tmpArticle.categories.clear(); - // loop through all categories strings and create a new category if a new one; also adds the categorys to the article + // loop through all categories strings and create a new category if a new one; + // also adds the categorys to the article for (String category : separatedCategories) { - oldArticle.categories.add(categoryRepository.findCategoryByName(category.trim()) + tmpArticle.categories.add(categoryRepository.findCategoryByName(category.trim()) .orElseGet(() -> new Category(category.trim()))); } - oldArticle.shouldReorder = shouldReorder; - oldArticle.reorderMaxPrice = (int) (Float.parseFloat(reorderMaxPrice) * 100); - oldArticle.shopPricePerUnitNetCent = (int) (Float.parseFloat(pricenetto) * 100); - oldArticle.warehouseUnitsPerSlot = Integer.parseInt(warehouseUnitsPerSlot); - oldArticle.title = title; - oldArticle.description = description; + tmpArticle.shouldReorder = shouldReorder; + tmpArticle.reorderMaxPrice = (int) (Float.parseFloat(reorderMaxPrice) * 100); + tmpArticle.shopPricePerUnitNetCent = (int) (Float.parseFloat(pricenetto) * 100); + tmpArticle.warehouseUnitsPerSlot = Integer.parseInt(warehouseUnitsPerSlot); + tmpArticle.title = title; + tmpArticle.description = description; - articleRepository.save(oldArticle); // save updated article + articleRepository.save(tmpArticle); // save updated article return new RedirectView("../"); // return to overview page + + } + + @PostMapping("/addArticle/{id}") + public RedirectView addArticle(@PathVariable(required = true) String id) { + // article is not already listed, create new one + int offeredArticleID = Integer.parseInt(id); + + Article tmpArticle = new Article(); + + ArticleOffer offeredArticle = offersRepository.findOfferedArticleById(offeredArticleID); + + // set default values + tmpArticle.description = ""; + tmpArticle.reorderMaxPrice = 0; + tmpArticle.shopPricePerUnitNetCent = offeredArticle.pricePerUnitNet; + tmpArticle.shouldReorder = false; + tmpArticle.title = offeredArticle.title; + tmpArticle.warehouseUnitsPerSlot = 1; + tmpArticle.image = articleRepository.findAll().get(0).image; // TODO set any static default image + tmpArticle.related = offeredArticle; + + articleRepository.save(tmpArticle); // save new article + + // return to edit article page + return new RedirectView("../" + articleRepository.findArticleIDByRelatedID(offeredArticleID).get()); } public static class UImodelArticles { @@ -115,13 +146,13 @@ public class InternArticleController { this.title = article.title; this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100)); this.price = String.format("%.2f", ((float) article.getPriceGross() / 100)); - + StringBuilder result = new StringBuilder(); for (Category temp : article.categories) { result.append(temp.name + " "); } - this.categorie = result.toString(); + this.categorie = result.toString(); this.stock = stock; this.offer_id = article.related.id; @@ -143,8 +174,7 @@ public class InternArticleController { public boolean shouldReorder; public String warehouseUnitsPerSlot; public String description; - - + public String getImgPath() { return imgPath; } @@ -246,15 +276,15 @@ public class InternArticleController { this.title = article.title; this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100)); this.price = String.format("%.2f", ((float) article.getPriceGross() / 100)); - + StringBuilder result = new StringBuilder(); for (Category temp : article.categories) { result.append(temp.name); result.append("\n"); } - this.categorie = result.toString(); - + this.categorie = result.toString(); + this.stock = stock; this.offer_id = article.related.id; this.id = article.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 1b467db..3ef21bf 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 @@ -1,5 +1,13 @@ package org.hso.ecommerce.controller.intern.suppliers; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.hso.ecommerce.entities.supplier.ArticleOffer; +import org.hso.ecommerce.repos.shop.ArticleRepository; +import org.hso.ecommerce.repos.shop.OffersRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -9,18 +17,140 @@ import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping("/intern/") public class SupplierOfferController { + @Autowired + private final OffersRepository offersRepository = null; + + @Autowired + private final ArticleRepository articleRepository = null; + @GetMapping("supplierOffers") public String internListedArticles(Model model) { - - - - - - - - return "intern/offeredArticles/index"; + List totals = new ArrayList(); + for (ArticleOffer article : offersRepository.findAll()) { + UImodelOfferedArticle tmp = new UImodelOfferedArticle(); + tmp.addData(article, "supplierName01", 4884, articleRepository.findArticleIDByRelatedID(article.id)); //TODO display supplier name with link + totals.add(tmp); + } + + model.addAttribute("OfferedArticles", totals); + return "intern/offeredArticles/index"; } + public class UImodelOfferedArticle { + + long offer_id; + String title; + String manufacturer; + String articlenumber; + String supplierName; + int supplierId; + 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 int getSupplierId() { + return supplierId; + } + + public void setSupplierId(int supplierId) { + this.supplierId = supplierId; + } + + 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 void addData(ArticleOffer article, String supplierName, int supplierId, + Optional listedArticleId) { + + this.offer_id = article.id; + this.title = article.title; + this.manufacturer = article.manufacturer; + this.articlenumber = article.articleNumber; + this.supplierName = supplierName; + this.supplierId = supplierId; + this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100)); + this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein"; + + if (listedArticleId.isPresent()) { + // this offer is listed --> show link + this.listedArticleId = listedArticleId.get(); + offerIsListed = true; + } else { + // this offer is not listed + offerIsListed = false; + } + } + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index ae86659..405fb4a 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -14,6 +14,12 @@ public class ArticleOffer { @NotNull public String manufacturer; + + @NotNull + public String title; + + @NotNull + public int pricePerUnitNet; @NotNull public String articleNumber; @@ -21,4 +27,6 @@ public class ArticleOffer { public int vatPercent; public boolean shouldBeAdvertised; + + } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index bd2b110..0340f59 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface ArticleRepository extends JpaRepository { @@ -26,6 +27,9 @@ public interface ArticleRepository extends JpaRepository { @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a WHERE c.id = :customerId ORDER BY co.id DESC") List
getOrderedArticles(long customerId); + @Query(value = "SELECT a.id FROM articles a WHERE a.related_id = :relatedId", nativeQuery = true) + Optional findArticleIDByRelatedID(@Param("relatedId") long relatedId); + @Query(value = "Select a.* from articles as a, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and a.title LIKE %:term% group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true) List
getArticlesByTerm(String term); diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/OffersRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/OffersRepository.java new file mode 100644 index 0000000..20a3f90 --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/OffersRepository.java @@ -0,0 +1,20 @@ +package org.hso.ecommerce.repos.shop; + +import java.util.List; + +import org.hso.ecommerce.entities.supplier.ArticleOffer; +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 OffersRepository extends JpaRepository { + + @Query("SELECT a FROM ArticleOffer a") + List findAll(); + + @Query("SELECT a FROM ArticleOffer a WHERE a.id = :offeredarticleId") + ArticleOffer findOfferedArticleById(@Param("offeredarticleId") long offeredarticleId); + +} diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/warehouse/WarehouseBookingPositionSlotEntryRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/warehouse/WarehouseBookingPositionSlotEntryRepository.java index b342a06..cb9902e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/warehouse/WarehouseBookingPositionSlotEntryRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/warehouse/WarehouseBookingPositionSlotEntryRepository.java @@ -15,7 +15,7 @@ public interface WarehouseBookingPositionSlotEntryRepository extends JpaReposito List getByArticle(long article); - @Query(value = "SELECT SUM(w.new_sum_articles) FROM warehouse_booking_position_entries as w WHERE w.article_id = :articleid", nativeQuery = true) + @Query(value = "SELECT SUM(w.new_sum_slot) FROM warehouse_booking_position_entries as w WHERE w.article_id = :articleid", nativeQuery = true) Optional getArticleStock(long articleid); } diff --git a/prototype/src/main/resources/templates/intern/listedArticles/id.html b/prototype/src/main/resources/templates/intern/listedArticles/id.html index 295bf80..7050d3c 100644 --- a/prototype/src/main/resources/templates/intern/listedArticles/id.html +++ b/prototype/src/main/resources/templates/intern/listedArticles/id.html @@ -1,118 +1,109 @@ - - - - - - Bearbeiten: Artikel - - - - - - - -
- -
-

Gelisteter Artikel ID

- - -
- -

- - -

-

- - - Details -

-
-
-

- - -

-

- -

-
-
-

- -  EUR
- (19% Mwst.) -
- =  EUR Brutto -

-

- -  EUR -

-
-
+ + + + Bearbeiten: Artikel + + + + + + +
+ +
+

Gelisteter Artikel ID

+ +

+ + +

+

+ + + + + + Details +

+
+
+

+ + +

+

+ +

+
+
+

+ +  EUR
+ (19% Mwst.) +
+ =  EUR Brutto +

+

+ +  EUR +

+
+


-
-
-
- -
- -

- Bitte jede Kategorien in eine eigene Zeile -

- -
- -
-

- - -

-

- Lagerbestand: -

-

- Der Wert wird nur für zukünftige Lagerbuchungen verwendet. - Bei Problemen kann können Einheiten aus- und wieder eingebucht werden. - -

-

- Lagerbuchung - -

-
- -

- - -

-
- - - -
- -
-
-
- - +
+
+

+ + +

+

+ Lagerbestand: +

+

+ Der Wert wird nur für zukünftige Lagerbuchungen verwendet. + Bei Problemen kann können Einheiten aus- und wieder eingebucht werden. + +

+

+ Lagerbuchung +

+
+

+ + +

+
+ + + +
+ +
+
+
+ diff --git a/prototype/src/main/resources/templates/intern/listedArticles/index.html b/prototype/src/main/resources/templates/intern/listedArticles/index.html index 94be11c..2840417 100644 --- a/prototype/src/main/resources/templates/intern/listedArticles/index.html +++ b/prototype/src/main/resources/templates/intern/listedArticles/index.html @@ -1,73 +1,69 @@ - - - - - - Gelistete Artikel - - - - - - - -
- -
-

- Weitere Artikel können über Artikelübersicht der Lieferanten hinzugefügt werden. - Jetzt Hinzufügen -

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
BildNamePreis(Netto)KategorienLagerbestandAngebots IDArtikel IDAktion
-

-

-
-
- - - + + + + Gelistete Artikel + + + + + + +
+ +
+

+ Weitere Artikel können über Artikelübersicht der Lieferanten hinzugefügt werden. + Jetzt Hinzufügen +

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
BildNamePreis(Netto)KategorienLagerbestandAngebots IDArtikel IDAktion
+
+
+

+

+
+
+ + \ No newline at end of file diff --git a/prototype/src/main/resources/templates/intern/offeredArticles/index.html b/prototype/src/main/resources/templates/intern/offeredArticles/index.html index 9ba3279..7a18ccc 100644 --- a/prototype/src/main/resources/templates/intern/offeredArticles/index.html +++ b/prototype/src/main/resources/templates/intern/offeredArticles/index.html @@ -1,140 +1,69 @@ - - - - - - Händlerangebote - - - - - - - -
- -
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
NameHerstellerArtikelnummerLieferantKaufpreis (Netto)Werbungs-
anfrage
Status
KameraSonjizuK48431587EXGelistet 44048
Hans Guck GmbH584,50 EUR
Cheap AG84,54 EURX
Not Cheap AG184,54 EUR
EarbudsSonjizuG447#$XGelistet 448
Cheap AG50,54 EURX
MundschutzFarma CorpMu-15415Hinzufügen
Cheap AG150,54 EUR
Not Cheap AG250,54 EUR
GoldbarenBundesbankG1KGInaktiv 4888
Cheap AG10000,54 EURX
-

-
-
-
- - - + + + + Händlerangebote + + + + + + +
+ +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
NameHerstellerArtikelnummerLieferantKaufpreis (Netto)Werbungs-
anfrage
Status
+ + +
+
+ +
+
+
+

+
+
+ + + \ No newline at end of file