add offered article to listed article
This commit is contained in:
parent
d8032c2bd7
commit
9cfb1cd0ad
Binary file not shown.
|
@ -5,8 +5,10 @@ import java.util.List;
|
||||||
|
|
||||||
import org.hso.ecommerce.entities.shop.Article;
|
import org.hso.ecommerce.entities.shop.Article;
|
||||||
import org.hso.ecommerce.entities.shop.Category;
|
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.ArticleRepository;
|
||||||
import org.hso.ecommerce.repos.shop.CategoryRepository;
|
import org.hso.ecommerce.repos.shop.CategoryRepository;
|
||||||
|
import org.hso.ecommerce.repos.shop.OffersRepository;
|
||||||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -26,6 +28,9 @@ public class InternArticleController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private final CategoryRepository categoryRepository = null;
|
private final CategoryRepository categoryRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final OffersRepository offersRepository = null;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String internListedArticles(Model model) {
|
public String internListedArticles(Model model) {
|
||||||
|
|
||||||
|
@ -57,39 +62,65 @@ public class InternArticleController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/saveChanges")
|
@PostMapping("/{id}/saveChanges")
|
||||||
public RedirectView saveChanges(
|
public RedirectView saveChanges(@PathVariable(required = true) int id,
|
||||||
@PathVariable int id,
|
@RequestParam(value = "title", required = true) String title,
|
||||||
@RequestParam("title") String title,
|
@RequestParam(value = "description", required = true) String description,
|
||||||
@RequestParam("description") String description,
|
@RequestParam(value = "units-per-slot", required = true) String warehouseUnitsPerSlot,
|
||||||
@RequestParam("units-per-slot") String warehouseUnitsPerSlot,
|
@RequestParam(value = "price_netto", required = true) String pricenetto,
|
||||||
@RequestParam("price_netto") String pricenetto,
|
@RequestParam(value = "reorderMaxPrice", required = true) String reorderMaxPrice,
|
||||||
@RequestParam("reorderMaxPrice") String reorderMaxPrice,
|
@RequestParam(value = "autobuy", required = true) Boolean shouldReorder,
|
||||||
@RequestParam("autobuy") Boolean shouldReorder,
|
@RequestParam(value = "categories", required = true) String categories) {
|
||||||
@RequestParam("categories") String categories) {
|
|
||||||
|
|
||||||
Article oldArticle = articleRepository.findArticleById(id);
|
Article tmpArticle = articleRepository.findArticleById(id); // get the old article
|
||||||
|
|
||||||
// TODO img
|
// TODO img
|
||||||
|
|
||||||
String[] separatedCategories = categories.split("\n");
|
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) {
|
for (String category : separatedCategories) {
|
||||||
oldArticle.categories.add(categoryRepository.findCategoryByName(category.trim())
|
tmpArticle.categories.add(categoryRepository.findCategoryByName(category.trim())
|
||||||
.orElseGet(() -> new Category(category.trim())));
|
.orElseGet(() -> new Category(category.trim())));
|
||||||
}
|
}
|
||||||
|
|
||||||
oldArticle.shouldReorder = shouldReorder;
|
tmpArticle.shouldReorder = shouldReorder;
|
||||||
oldArticle.reorderMaxPrice = (int) (Float.parseFloat(reorderMaxPrice) * 100);
|
tmpArticle.reorderMaxPrice = (int) (Float.parseFloat(reorderMaxPrice) * 100);
|
||||||
oldArticle.shopPricePerUnitNetCent = (int) (Float.parseFloat(pricenetto) * 100);
|
tmpArticle.shopPricePerUnitNetCent = (int) (Float.parseFloat(pricenetto) * 100);
|
||||||
oldArticle.warehouseUnitsPerSlot = Integer.parseInt(warehouseUnitsPerSlot);
|
tmpArticle.warehouseUnitsPerSlot = Integer.parseInt(warehouseUnitsPerSlot);
|
||||||
oldArticle.title = title;
|
tmpArticle.title = title;
|
||||||
oldArticle.description = description;
|
tmpArticle.description = description;
|
||||||
|
|
||||||
articleRepository.save(oldArticle); // save updated article
|
articleRepository.save(tmpArticle); // save updated article
|
||||||
return new RedirectView("../"); // return to overview page
|
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 {
|
public static class UImodelArticles {
|
||||||
|
@ -144,7 +175,6 @@ public class InternArticleController {
|
||||||
public String warehouseUnitsPerSlot;
|
public String warehouseUnitsPerSlot;
|
||||||
public String description;
|
public String description;
|
||||||
|
|
||||||
|
|
||||||
public String getImgPath() {
|
public String getImgPath() {
|
||||||
return imgPath;
|
return imgPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,16 @@ package org.hso.ecommerce.controller.intern.suppliers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
||||||
import org.hso.ecommerce.repos.shop.CategoryRepository;
|
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||||
import org.hso.ecommerce.repos.shop.OffersRepository;
|
import org.hso.ecommerce.repos.shop.OffersRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/intern/")
|
@RequestMapping("/intern/")
|
||||||
|
@ -21,6 +20,9 @@ public class SupplierOfferController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private final OffersRepository offersRepository = null;
|
private final OffersRepository offersRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final ArticleRepository articleRepository = null;
|
||||||
|
|
||||||
@GetMapping("supplierOffers")
|
@GetMapping("supplierOffers")
|
||||||
public String internListedArticles(Model model) {
|
public String internListedArticles(Model model) {
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ public class SupplierOfferController {
|
||||||
|
|
||||||
for (ArticleOffer article : offersRepository.findAll()) {
|
for (ArticleOffer article : offersRepository.findAll()) {
|
||||||
UImodelOfferedArticle tmp = new UImodelOfferedArticle();
|
UImodelOfferedArticle tmp = new UImodelOfferedArticle();
|
||||||
tmp.addData(article,"supplierName01", 4884, 5);
|
tmp.addData(article, "supplierName01", 4884, articleRepository.findArticleIDByRelatedID(article.id)); //TODO display supplier name with link
|
||||||
totals.add(tmp);
|
totals.add(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ public class SupplierOfferController {
|
||||||
|
|
||||||
public class UImodelOfferedArticle {
|
public class UImodelOfferedArticle {
|
||||||
|
|
||||||
|
long offer_id;
|
||||||
String title;
|
String title;
|
||||||
String manufacturer;
|
String manufacturer;
|
||||||
String articlenumber;
|
String articlenumber;
|
||||||
|
@ -46,6 +49,23 @@ public class SupplierOfferController {
|
||||||
String price;
|
String price;
|
||||||
String ads;
|
String ads;
|
||||||
int listedArticleId;
|
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() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
|
@ -111,8 +131,10 @@ public class SupplierOfferController {
|
||||||
this.listedArticleId = listedArticleId;
|
this.listedArticleId = listedArticleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addData(ArticleOffer article, String supplierName, int supplierId, int listedArticleId) {
|
public void addData(ArticleOffer article, String supplierName, int supplierId,
|
||||||
|
Optional<Integer> listedArticleId) {
|
||||||
|
|
||||||
|
this.offer_id = article.id;
|
||||||
this.title = article.title;
|
this.title = article.title;
|
||||||
this.manufacturer = article.manufacturer;
|
this.manufacturer = article.manufacturer;
|
||||||
this.articlenumber = article.articleNumber;
|
this.articlenumber = article.articleNumber;
|
||||||
|
@ -120,9 +142,15 @@ public class SupplierOfferController {
|
||||||
this.supplierId = supplierId;
|
this.supplierId = supplierId;
|
||||||
this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100));
|
this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100));
|
||||||
this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein";
|
this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein";
|
||||||
this.listedArticleId = listedArticleId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (listedArticleId.isPresent()) {
|
||||||
|
// this offer is listed --> show link
|
||||||
|
this.listedArticleId = listedArticleId.get();
|
||||||
|
offerIsListed = true;
|
||||||
|
} else {
|
||||||
|
// this offer is not listed
|
||||||
|
offerIsListed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||||
|
@ -26,5 +27,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||||
@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")
|
@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<Article> getOrderedArticles(long customerId);
|
List<Article> getOrderedArticles(long customerId);
|
||||||
|
|
||||||
|
@Query(value = "SELECT a.id FROM articles a WHERE a.related_id = :relatedId", nativeQuery = true)
|
||||||
|
Optional<Integer> findArticleIDByRelatedID(@Param("relatedId") long relatedId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -13,4 +14,7 @@ public interface OffersRepository extends JpaRepository<ArticleOffer, Long> {
|
||||||
@Query("SELECT a FROM ArticleOffer a")
|
@Query("SELECT a FROM ArticleOffer a")
|
||||||
List<ArticleOffer> findAll();
|
List<ArticleOffer> findAll();
|
||||||
|
|
||||||
|
@Query("SELECT a FROM ArticleOffer a WHERE a.id = :offeredarticleId")
|
||||||
|
ArticleOffer findOfferedArticleById(@Param("offeredarticleId") long offeredarticleId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,12 @@
|
||||||
</p>
|
</p>
|
||||||
<p class="s">
|
<p class="s">
|
||||||
<label for="ref-article">Refernzierter Artikel</label>
|
<label for="ref-article">Refernzierter Artikel</label>
|
||||||
<input class="" type="text" name="ref-article" th:value="${ArticleID.offer_id}" disabled/>
|
<input class="" type="text" th:value="${ArticleID.offer_id}" disabled/>
|
||||||
|
|
||||||
|
<input type="hidden" th:value="${ArticleID.offer_id}" name="ref-article" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<td><a th:href="${'/intern/supplierOffers/#q=' + {ArticleID.id}}">Details</a></td>
|
<td><a th:href="${'/intern/supplierOffers/#q=' + {ArticleID.id}}">Details</a></td>
|
||||||
</p>
|
</p>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
|
|
|
@ -47,7 +47,17 @@
|
||||||
<td><a th:href="@{/intern/suppliers/{id}(id = ${article.supplierId})}" th:text="${article.supplierName}"></a></td>
|
<td><a th:href="@{/intern/suppliers/{id}(id = ${article.supplierId})}" th:text="${article.supplierName}"></a></td>
|
||||||
<td><span th:text="${article.price}"></span> €</td>
|
<td><span th:text="${article.price}"></span> €</td>
|
||||||
<td><span th:text="${article.ads}"></span></td>
|
<td><span th:text="${article.ads}"></span></td>
|
||||||
<td><a th:href="@{/intern/articles/{id}(id = ${article.listedArticleId})}" th:text="${article.listedArticleId}"></a></td>
|
<td>
|
||||||
|
<div th:if="${article.offerIsListed}">
|
||||||
|
<a th:href="@{/intern/articles/{id}(id = ${article.listedArticleId})}">Artikel gelistet</a>
|
||||||
|
</div>
|
||||||
|
<!-- ELSE -->
|
||||||
|
<div th:unless="${article.offerIsListed}">
|
||||||
|
<form class="detailgrid" action="#" th:action="@{/intern/articles/addArticle/{id}(id = ${article.offer_id})}" method="POST">
|
||||||
|
<input type="submit" value="Hinzufügen" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Reference in New Issue