diff --git a/prototype/build.gradle b/prototype/build.gradle index 2769783..ad8b14c 100644 --- a/prototype/build.gradle +++ b/prototype/build.gradle @@ -35,5 +35,5 @@ group 'org.hso' version '0.1.0' bootRun { - args = ["--spring.profiles.active=dev"] + args = ["--spring.profiles.active=dev --spring.config.location=classpath:/application.properties\""] } 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 29fe361..c79cc6d 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 @@ -1,57 +1,81 @@ package org.hso.ecommerce.controller.intern; - - +import java.util.ArrayList; import java.util.List; import org.hso.ecommerce.entities.shop.Article; import org.hso.ecommerce.repos.shop.ArticleRepository; +import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; - - - @Controller @RequestMapping("intern/listedArticles") -public class InternArticleController { - - @Autowired - private final ArticleRepository articleRepository = null; - - /* - @Autowired - public InternArticleController(ArticleRepository articleRepository) - { - this.articleRepository = articleRepository; - } - */ - - @GetMapping("/") - public String internListedArticles(Model model) { - +public class InternArticleController +{ + @Autowired + private final ArticleRepository articleRepository = null; - List
articles = articleRepository.findAll(); - - System.out.println(articles.size()); + @Autowired + private final WarehouseBookingPositionSlotEntryRepository warehouseEntryRepository = null; + @GetMapping("/") + public String internListedArticles(Model model) + { - - // model.addAttribute("ListedArticles", bookService.findAll()); + List totals = new ArrayList(); - - - return "intern/listedArticles/index"; - } - - - - @GetMapping("/{id}") - public String internListedArticlesId() { - return "intern/listedArticles/id"; - } + for (Article article : articleRepository.findAll()) { + ListedArticlesListTotals tmp = new ListedArticlesListTotals(); + tmp.addListedArticle(article, + warehouseEntryRepository.getArticleStock(article.id).orElse(0)); + totals.add(tmp); + } + + model.addAttribute("ListedArticles", totals); + return "intern/listedArticles/index"; + } + + @GetMapping("/{id}") + public String internListedArticlesId() + { + return "intern/listedArticles/id"; + } + + public static class ListedArticlesListTotals + { + + public String imgPath; + + public String title; + + public String price; + + public String price_netto; + + public String categorie; + + public int stock; + + public long offer_id; + + public long id; + + void addListedArticle(Article article, int stock) + { + this.imgPath = article.image.path; + this.title = article.title; + this.price_netto = String.format("%.2f", + ((float) article.shopPricePerUnitNetCent / 100)); + this.price = String.format("%.2f", + ((float) article.getPriceGross() / 100)); + this.categorie = article.getCategories(); + this.stock = stock; + this.offer_id = article.related.id; + this.id = article.id; + } + } - } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java index a26cb39..ed351ea 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java @@ -9,41 +9,55 @@ import java.util.Set; @Entity @Table(name = "articles") -public class Article { +public class Article +{ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Basic - public long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Basic + public long id; - @ManyToOne(optional = false) - public ArticleOffer related; + @ManyToOne(optional = false) + public ArticleOffer related; - public int shopPricePerUnitNetCent; - public int warehouseUnitsPerSlot; + public int shopPricePerUnitNetCent; - public boolean shouldReorder; - public int reorderMaxPrice; + public int warehouseUnitsPerSlot; - @NotNull - public String title; + public boolean shouldReorder; - @NotNull - public String description; + public int reorderMaxPrice; - @OneToOne(optional = true) - @Basic(fetch = FetchType.LAZY) - public Image image; + @NotNull + public String title; - @ManyToMany - @JoinTable(name = "article_categories_bindings") - public Set categories = new HashSet<>(); + @NotNull + public String description; - public int getVat() { - return (shopPricePerUnitNetCent * related.vatPercent) / 100; - } + @OneToOne(optional = true) + @Basic(fetch = FetchType.LAZY) + public Image image; - public int getPriceGross() { - return shopPricePerUnitNetCent + getVat(); - } + @ManyToMany + @JoinTable(name = "article_categories_bindings") + public Set categories = new HashSet<>(); + + public String getCategories() + { + StringBuilder result = new StringBuilder(); + for (Category temp : categories) { + result.append(temp.name); + } + return result.toString(); + } + + public int getVat() + { + return (shopPricePerUnitNetCent * related.vatPercent) / 100; + } + + public int getPriceGross() + { + return shopPricePerUnitNetCent + getVat(); + } } diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Category.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Category.java index 13b0b54..242826d 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Category.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Category.java @@ -1,7 +1,5 @@ package org.hso.ecommerce.entities.shop; -import org.hso.ecommerce.entities.shop.Article; - import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.HashSet; 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 27223db..93803cc 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 @@ -1,14 +1,12 @@ package org.hso.ecommerce.repos.shop; import org.hso.ecommerce.entities.shop.Article; -import org.hso.ecommerce.entities.user.User; 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; import java.util.List; -import java.util.Optional; @Repository public interface ArticleRepository extends JpaRepository 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 962231a..e1327ce 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 @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface WarehouseBookingPositionSlotEntryRepository extends JpaRepository { @@ -14,5 +15,10 @@ public interface WarehouseBookingPositionSlotEntryRepository extends JpaReposito // @Query("SELECT e FROM WarehouseBookingPositionSlotEntry e, Slot s WHERE e.slot = s AND e.article = :article GROUP BY e.slot.slotNum HAVING max(e.id)") @Query(value = "Select e.id, e.article_id, e.new_sum_slot, e.slot_id from warehouse_booking_position_entries as e, warehouse_slots as s where e.slot_id = s.id AND e.article_id = :article GROUP BY s.slot_num HAVING max(e.id)", nativeQuery = true) 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) + Optional getArticleStock(long articleid); + } diff --git a/prototype/src/main/resources/templates/intern/listedArticles/index.html b/prototype/src/main/resources/templates/intern/listedArticles/index.html index adce5ef..321835b 100644 --- a/prototype/src/main/resources/templates/intern/listedArticles/index.html +++ b/prototype/src/main/resources/templates/intern/listedArticles/index.html @@ -38,67 +38,30 @@ data-target-id="main-table"> + Bild Name Preis (Netto) Kategorien - Lagerbestand (Aktiv) - Artikel - Id (bearbeiten) - - - - - KameraÖ - 100,50 EUR - (84.45 EUR) - Úberwachung, Elektronik - 301 - 5051 - 890 - - - - Earbuds - 63,95 EUR - (53,73 EUR) - Kopfhörer, Elektronik - 12 - 840 - 13850 - - - - USB-Magic Light - 11,90 EUR - (10,00 EUR) - Sonstiges, Elektronik - 3 - 8401 - 5784 - - - - 3D Magic Stativ - 15,99 EUR - (13.44 EUR) - Úberwachung, Elektronik - 4 - 2135 - 4564 - - - - Ersatzfernbedinung - 7,95 EUR - (6.68 EUR) - Úberwachung, Elektronik - 0 - 4565 - 4566 + Lagerbestand + Angebot + ID + + + + + + + + + + + + +