show listedArticles
This commit is contained in:
		@ -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\""]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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<Article> 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<ListedArticlesListTotals> totals = new ArrayList<ListedArticlesListTotals>();
 | 
			
		||||
 | 
			
		||||
   	
 | 
			
		||||
   	
 | 
			
		||||
       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;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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<Category> 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<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();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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<Article, Long>
 | 
			
		||||
 | 
			
		||||
@ -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<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(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);
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    @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);
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -38,67 +38,30 @@
 | 
			
		||||
                           data-target-id="main-table"></input>
 | 
			
		||||
                </th>
 | 
			
		||||
            </tr>
 | 
			
		||||
            <thead>
 | 
			
		||||
            <tr>
 | 
			
		||||
                <th>Bild</th>
 | 
			
		||||
                <th>Name</th>
 | 
			
		||||
                <th>Preis</th>
 | 
			
		||||
                <th>(Netto)</th>
 | 
			
		||||
                <th>Kategorien</th>
 | 
			
		||||
                <th>Lagerbestand (Aktiv)</th>
 | 
			
		||||
                <th>Artikel</th>
 | 
			
		||||
                <th>Id (bearbeiten)</th>
 | 
			
		||||
            </tr>
 | 
			
		||||
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td><img th:src="@{/img/product-1.jpg}" class="s"/></td>
 | 
			
		||||
                <td>KameraÖ</td>
 | 
			
		||||
                <td>100,50 EUR</td>
 | 
			
		||||
                <td> (84.45 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 EUR</td>
 | 
			
		||||
                <td>(53,73 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 EUR</td>
 | 
			
		||||
                <td> (10,00 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 EUR</td>
 | 
			
		||||
                <td> (13.44 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 EUR</td>
 | 
			
		||||
                <td> (6.68 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>
 | 
			
		||||
                <th>Lagerbestand</th>
 | 
			
		||||
                <th>Angebot</th>
 | 
			
		||||
                <th>ID</th>
 | 
			
		||||
            </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>
 | 
			
		||||
        <p>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user