WIP feature/listedArticles #15

Merged
Seil0 merged 33 commits from feature/listedArticles into master 2020-05-15 19:48:22 +02:00
7 changed files with 127 additions and 124 deletions
Showing only changes of commit a2f20938cd - Show all commits

View File

@ -35,5 +35,5 @@ group 'org.hso'
version '0.1.0' version '0.1.0'
bootRun { bootRun {
args = ["--spring.profiles.active=dev"] args = ["--spring.profiles.active=dev --spring.config.location=classpath:/application.properties\""]
} }

View File

@ -1,57 +1,81 @@
package org.hso.ecommerce.controller.intern; package org.hso.ecommerce.controller.intern;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hso.ecommerce.entities.shop.Article; import org.hso.ecommerce.entities.shop.Article;
import org.hso.ecommerce.repos.shop.ArticleRepository; import org.hso.ecommerce.repos.shop.ArticleRepository;
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;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@Controller @Controller
@RequestMapping("intern/listedArticles") @RequestMapping("intern/listedArticles")
public class InternArticleController { public class InternArticleController
{
@Autowired @Autowired
private final ArticleRepository articleRepository = null; private final ArticleRepository articleRepository = null;
/*
@Autowired
public InternArticleController(ArticleRepository articleRepository)
{
this.articleRepository = articleRepository;
}
*/
@GetMapping("/")
public String internListedArticles(Model model) {
List<Article> articles = articleRepository.findAll(); @Autowired
private final WarehouseBookingPositionSlotEntryRepository warehouseEntryRepository = null;
System.out.println(articles.size());
@GetMapping("/")
public String internListedArticles(Model model)
{
List<ListedArticlesListTotals> totals = new ArrayList<ListedArticlesListTotals>();
// model.addAttribute("ListedArticles", bookService.findAll());
for (Article article : articleRepository.findAll()) {
ListedArticlesListTotals tmp = new ListedArticlesListTotals();
return "intern/listedArticles/index"; tmp.addListedArticle(article,
} warehouseEntryRepository.getArticleStock(article.id).orElse(0));
totals.add(tmp);
}
@GetMapping("/{id}") model.addAttribute("ListedArticles", totals);
public String internListedArticlesId() { return "intern/listedArticles/index";
return "intern/listedArticles/id"; }
}
@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();
Outdated
Review

String[] separatedCategories

String[] separatedCategories
Review

fixed with a98782bc01

fixed with https://git.mosad.xyz/localhorst/e-commerce/commit/a98782bc01fcdd03b746a9030539fc2bdf9301c4
this.stock = stock;
this.offer_id = article.related.id;
this.id = article.id;
}
}
} }

View File

@ -9,41 +9,55 @@ import java.util.Set;
@Entity @Entity
@Table(name = "articles") @Table(name = "articles")
public class Article { public class Article
{
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic @Basic
public long id; public long id;
@ManyToOne(optional = false) @ManyToOne(optional = false)
public ArticleOffer related; public ArticleOffer related;
public int shopPricePerUnitNetCent; public int shopPricePerUnitNetCent;
public int warehouseUnitsPerSlot;
public boolean shouldReorder; public int warehouseUnitsPerSlot;
public int reorderMaxPrice;
@NotNull public boolean shouldReorder;
public String title;
@NotNull public int reorderMaxPrice;
public String description;
@OneToOne(optional = true) @NotNull
@Basic(fetch = FetchType.LAZY) public String title;
public Image image;
@ManyToMany @NotNull
@JoinTable(name = "article_categories_bindings") public String description;
public Set<Category> categories = new HashSet<>();
public int getVat() { @OneToOne(optional = true)
return (shopPricePerUnitNetCent * related.vatPercent) / 100; @Basic(fetch = FetchType.LAZY)
} public Image image;
public int getPriceGross() { @ManyToMany
return shopPricePerUnitNetCent + getVat(); @JoinTable(name = "article_categories_bindings")
} public Set<Category> 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();
}
} }

View File

@ -1,7 +1,5 @@
package org.hso.ecommerce.entities.shop; package org.hso.ecommerce.entities.shop;
import org.hso.ecommerce.entities.shop.Article;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.HashSet; import java.util.HashSet;

View File

@ -1,14 +1,12 @@
package org.hso.ecommerce.repos.shop; package org.hso.ecommerce.repos.shop;
import org.hso.ecommerce.entities.shop.Article; 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.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.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>

View File

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query;
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 WarehouseBookingPositionSlotEntryRepository extends JpaRepository<WarehouseBookingPositionSlotEntry, Long> { public interface WarehouseBookingPositionSlotEntryRepository extends JpaRepository<WarehouseBookingPositionSlotEntry, Long> {
@ -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("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) @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<WarehouseBookingPositionSlotEntry> getByArticle(long article); List<WarehouseBookingPositionSlotEntry> 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<Integer> getArticleStock(long articleid);
} }

View File

@ -38,67 +38,30 @@
data-target-id="main-table"></input> data-target-id="main-table"></input>
</th> </th>
</tr> </tr>
<thead>
<tr> <tr>
<th>Bild</th> <th>Bild</th>
<th>Name</th> <th>Name</th>
<th>Preis</th> <th>Preis</th>
<th>(Netto)</th> <th>(Netto)</th>
<th>Kategorien</th> <th>Kategorien</th>
<th>Lagerbestand (Aktiv)</th> <th>Lagerbestand</th>
<th>Artikel</th> <th>Angebot</th>
<th>Id (bearbeiten)</th> <th>ID</th>
</tr>
<tr>
<td><img th:src="@{/img/product-1.jpg}" class="s"/></td>
<td>KameraÖ</td>
<td>100,50&nbsp;EUR</td>
<td> (84.45&nbsp;EUR)</td>
<td>Úberwachung, Elektronik</td>
<td>301 <span class="checked"></span></td>
<td><a th:href="@{/intern/articles/#q=%2044048}">5051</a></td>
<td><a th:href="@{/intern/listedArticles/45015}">890</a></td>
</tr>
<tr>
<td><img th:src="@{/img/product-2.jpg}" class="s"/></td>
<td>Earbuds</td>
<td>63,95&nbsp;EUR</td>
<td>(53,73&nbsp;EUR)</td>
<td>Kopfhörer, Elektronik</td>
<td>12 <span class="checked"></span></td>
<td><a th:href="@{/intern/articles/#q=%2044048}">840</a></td>
<td><a th:href="@{/intern/listedArticles/45015}">13850</a></td>
</tr>
<tr>
<td><img th:src="@{/img/product-3.jpg}" class="s"/></td>
<td>USB-Magic Light</td>
<td>11,90&nbsp;EUR</td>
<td> (10,00&nbsp;EUR)</td>
<td>Sonstiges, Elektronik</td>
<td>3<span class="unchecked"></span></td>
<td><a th:href="@{/intern/articles/#q=%2044048}">8401</a></td>
<td><a th:href="@{/intern/listedArticles/45015}">5784</a></td>
</tr>
<tr>
<td><img th:src="@{/img/product-4.jpg}" class="s"/></td>
<td>3D Magic Stativ</td>
<td>15,99&nbsp;EUR</td>
<td> (13.44&nbsp;EUR)</td>
<td>Úberwachung, Elektronik</td>
<td>4<span class="checked"></span></td>
<td><a th:href="@{/intern/articles/#q=%2044048}">2135</a></td>
<td><a th:href="@{/intern/listedArticles/45015}">4564</a></td>
</tr>
<tr>
<td><img th:src="@{/img/product-5.jpg}" class="s"/></td>
<td>Ersatzfernbedinung</td>
<td>7,95&nbsp;EUR</td>
<td> (6.68&nbsp;EUR)</td>
<td>Úberwachung, Elektronik</td>
<td>0<span class="checked"></span></td>
<td><a th:href="@{/intern/articles/#q=%2044048}">4565</a></td>
<td><a th:href="@{/intern/listedArticles/45015}">4566</a></td>
</tr> </tr>
</thead>
<tbody>
<tr th:each="article : ${ListedArticles}">
<td><img th:src="${article.imgPath}" class="s"/></td>
<td><span th:text="${article.title}"></span></td>
<td><span th:text="${article.price}"></span></td>
<td><span th:text="${article.price_netto}"></span></td>
<td><span th:text="${article.categorie}"></span></td>
<td><span th:text="${article.stock}"></span></td>
<td><a th:href="@{/intern/articles/{id}(id = ${article.offer_id})}" th:text="${article.offer_id}"></a></td>
<td><a th:href="@{/intern/listedArticles/{id}(id = ${article.id})}" th:text="${article.id}"></a></td>
</tr>
</tbody>
</table> </table>
<p> <p>
</div> </div>