1
0
Fork 0

Add purchase to detail

This commit is contained in:
Ethanell 2022-06-29 21:44:24 +02:00
parent c3975ab084
commit da71ada2b8
8 changed files with 264 additions and 26 deletions

View file

@ -56,11 +56,19 @@
</p> </p>
<p> <p>
<label for="manufacturerId">Manufacturer</label> <label for="manufacturerId">Manufacturer</label>
<input type="number" name="manufacturerId" value="${result.manufacturerId}" size="30" id="manufacturerId" /> <select name="manufacturerId" id="manufacturerId">
<c:forEach items="${manufacturers}" var="manufacturer">
<option <c:if test="${manufacturer.manufacturerId == result.manufacturerId}">selected </c:if>value="${manufacturer.manufacturerId}">${manufacturer.name}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="productCode">Product Code</label> <label for="productCode">Product Code</label>
<input type="text" name="productCode" value="${result.productCode}" size="2" id="productCode" /> <select name="productCode" id="productCode">
<c:forEach items="${productCodes}" var="productCode">
<option <c:if test="${productCode.prodCode == result.productCode}">selected </c:if>value="${productCode.prodCode}">${productCode.prodCode} - ${productCode.description}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="purchaseCost">Purchase cost</label> <label for="purchaseCost">Purchase cost</label>
@ -76,13 +84,56 @@
</p> </p>
<p> <p>
<label for="markup">Available</label> <label for="markup">Available</label>
<input type="text" name="available" value="${result.available}" id="available" size="5" /> <input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
</p> </p>
<p> <p>
<label for="description">Description</label> <label for="description">Description</label>
<input type="text" name="description" value="${result.description}" id="description" size="50" /> <input type="text" name="description" value="${result.description}" id="description" size="50" />
</p> </p>
</c:when> </c:when>
<c:when test="${type == 'purchase'}">
<p>result: ${result}</p>
<p>
<label for="orderNum">Order number</label>
<input type="number" name="orderNum" value="${result.orderNum}" id="orderNum" />
</p>
<p>
<label for="customerId">Customer</label>
<select name="customerId" id="customerId">
<c:forEach items="${customers}" var="customer">
<option <c:if test="${customer.customerId == result.customerId}">selected </c:if>value="${customer.customerId}">${customer.name}</option>
</c:forEach>
</select>
</p>
<p>
<label for="productId">Product</label>
<select name="productId" id="productId">
<c:forEach items="${products}" var="product">
<option <c:if test="${product.productId == result.productId}">selected </c:if>value="${product.productId}">${product.description}</option>
</c:forEach>
</select>
</p>
<p>
<label for="quantity">Quantity</label>
<input type="number" name="quantity" value="${result.quantity}" id="quantity" />
</p>
<p>
<label for="shippingCost">Shipping cost</label>
<input type="number" name="shippingCost" value="${result.shippingCost}" id="shippingCost" />
</p>
<p>
<label for="salesDate">Sales date</label>
<input type="number" name="salesDate" value="${result.salesDate}" id="salesDate" />
</p>
<p>
<label for="shippingDate">Shipping date</label>
<input type="date" name="shippingDate" value="${result.shippingDate}" id="shippingDate" />
</p>
<p>
<label for="freightCompany">Freight company</label>
<input type="text" name="freightCompany" value="${result.freightCompany}" id="freightCompany" />
</p>
</c:when>
</c:choose> </c:choose>
<input hidden type="text" name="type" value="${type}" /> <input hidden type="text" name="type" value="${type}" />

View file

@ -56,11 +56,19 @@
</p> </p>
<p> <p>
<label for="manufacturerId">Manufacturer</label> <label for="manufacturerId">Manufacturer</label>
<input type="number" name="manufacturerId" value="${result.manufacturerId}" size="30" id="manufacturerId" /> <select name="manufacturerId" id="manufacturerId">
<c:forEach items="${manufacturers}" var="manufacturer">
<option <c:if test="${manufacturer.manufacturerId == result.manufacturerId}">selected </c:if>value="${manufacturer.manufacturerId}">${manufacturer.name}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="productCode">Product Code</label> <label for="productCode">Product Code</label>
<input type="text" name="productCode" value="${result.productCode}" size="2" id="productCode" /> <select name="productCode" id="productCode">
<c:forEach items="${productCodes}" var="productCode">
<option <c:if test="${productCode.prodCode == result.productCode}">selected </c:if>value="${productCode.prodCode}">${productCode.prodCode} - ${productCode.description}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="purchaseCost">Purchase cost</label> <label for="purchaseCost">Purchase cost</label>
@ -76,13 +84,55 @@
</p> </p>
<p> <p>
<label for="markup">Available</label> <label for="markup">Available</label>
<input type="text" name="available" value="${result.available}" id="available" size="5" /> <input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
</p> </p>
<p> <p>
<label for="description">Description</label> <label for="description">Description</label>
<input type="text" name="description" value="${result.description}" id="description" size="50" /> <input type="text" name="description" value="${result.description}" id="description" size="50" />
</p> </p>
</c:when> </c:when>
<c:when test="${type == 'purchase'}">
<p>
<label for="orderNum">Order number</label>
<input type="number" name="orderNum" value="${result.orderNum}" id="orderNum" />
</p>
<p>
<label for="customerId">Customer</label>
<select name="customerId" id="customerId">
<c:forEach items="${customers}" var="customer">
<option <c:if test="${customer.customerId == result.customerId}">selected </c:if>value="${customer.customerId}">${customer.name}</option>
</c:forEach>
</select>
</p>
<p>
<label for="productId">Product</label>
<select name="productId" id="productId">
<c:forEach items="${products}" var="product">
<option <c:if test="${product.productId == result.productId}">selected </c:if>value="${product.productId}">${product.description}</option>
</c:forEach>
</select>
</p>
<p>
<label for="quantity">Quantity</label>
<input type="number" name="quantity" value="${result.quantity}" id="quantity" />
</p>
<p>
<label for="shippingCost">Shipping cost</label>
<input type="number" name="shippingCost" value="${result.shippingCost}" id="shippingCost" />
</p>
<p>
<label for="salesDate">Sales date</label>
<input type="date" name="salesDate" value="${result.salesDate}" id="salesDate" />
</p>
<p>
<label for="shippingDate">Shipping date</label>
<input type="date" name="shippingDate" value="${result.shippingDate}" id="shippingDate" />
</p>
<p>
<label for="freightCompany">Freight company</label>
<input type="text" name="freightCompany" value="${result.freightCompany}" id="freightCompany" />
</p>
</c:when>
</c:choose> </c:choose>
<input hidden type="text" name="type" value="${type}" /> <input hidden type="text" name="type" value="${type}" />

View file

@ -3,8 +3,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group> <group>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/Product.hbm.xml</file> <file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/detail.jsp</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/menu.jsp</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/resultat.jsp</file> <file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/resultat.jsp</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/controller/BddController.java</file> <file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/controller/BddController.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/MagasinHelper.java</file> <file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/MagasinHelper.java</file>

View file

@ -25,7 +25,7 @@ public class MagasinHelper {
this.session = HibernateUtil.getSessionFactory().openSession(); this.session = HibernateUtil.getSessionFactory().openSession();
} }
public List getProducts(){ public List getProductsColums(){
List <Product> resultat=null; List <Product> resultat=null;
Transaction tx=null; Transaction tx=null;
try{ try{
@ -46,6 +46,27 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List<Product> getProducts(){
List<Product> resultat=null;
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Query q=session.createQuery("from Product p");
resultat=q.list();
} catch (Exception e) {
e.printStackTrace();
} finally{
if (session.isOpen())session.close();
}
return resultat;
}
public Product getProduct(int id){ public Product getProduct(int id){
Product resultat=null; Product resultat=null;
Transaction tx=null; Transaction tx=null;
@ -68,7 +89,7 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List getClients(){ public List getClientsColums(){
List <Customer> resultat=null; List <Customer> resultat=null;
Transaction tx=null; Transaction tx=null;
try{ try{
@ -91,6 +112,30 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List<Customer> getClients(){
List<Customer> resultat=null;
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Query q=session.createQuery("from Customer c");
resultat=q.list();
}
catch (Exception e) {
e.printStackTrace();
}
finally{
if (session.isOpen())session.close();
}
return resultat;
}
public List getClients(String name){ public List getClients(String name){
List resultat=null; List resultat=null;
Transaction tx=null; Transaction tx=null;
@ -114,6 +159,48 @@ public class MagasinHelper {
return resultat; return resultat;
} }
public List getManufacturers(){
List <Manufacturer> resultat=null;
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Query q=session.createQuery("from Manufacturer m");
resultat=q.list();
} catch (Exception e) {
e.printStackTrace();
} finally{
if (session.isOpen())session.close();
}
return resultat;
}
public List getProductCodes(){
List <ProductCode> resultat=null;
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Query q=session.createQuery("from ProductCode p");
resultat=q.list();
} catch (Exception e) {
e.printStackTrace();
} finally{
if (session.isOpen())session.close();
}
return resultat;
}
public List getDiscountCode(){ public List getDiscountCode(){
List resultat=null; List resultat=null;
Transaction tx=null; Transaction tx=null;
@ -274,7 +361,7 @@ public void deleteCustomer (int _id) {
} }
public List<PurchaseOrder> getPurchase(){ public List getPurchaseColums(){
List resultat=null; List resultat=null;
Transaction tx=null; Transaction tx=null;
try{ try{
@ -282,7 +369,7 @@ public void deleteCustomer (int _id) {
session.flush(); session.flush();
tx=session.beginTransaction(); tx=session.beginTransaction();
Query q=session.createQuery("select po.customerId, po.productId, po.quantity, po.shippingCost, po.salesDate, po.shippingDate, po.freightCompany from PurchaseOrder po"); Query q=session.createQuery("select po.orderNum, po.customerId, po.productId, po.quantity, po.shippingCost, po.salesDate, po.shippingDate, po.freightCompany from PurchaseOrder po");
resultat=(List<PurchaseOrder>)q.list(); resultat=(List<PurchaseOrder>)q.list();
} }
catch (Exception e) { catch (Exception e) {
@ -295,17 +382,17 @@ public void deleteCustomer (int _id) {
return resultat; return resultat;
} }
public List<PurchaseOrder> getPurchase(int id){ public PurchaseOrder getPurchase(int id){
List resultat=null; PurchaseOrder resultat=null;
Transaction tx=null; Transaction tx=null;
try{ try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush(); session.flush();
tx=session.beginTransaction(); tx=session.beginTransaction();
Query q=session.createQuery(" from PurchaseOrder a where a.customerId=:_id"); Query q=session.createQuery(" from PurchaseOrder p where p.orderNum = :_id");
q.setInteger("_id", id); q.setInteger("_id", id);
resultat=(List<PurchaseOrder>)q.list(); resultat=(PurchaseOrder)q.list().iterator().next();
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -69,16 +69,16 @@ public class BddController extends MultiActionController {
switch (type) { switch (type) {
case "customer": case "customer":
mv.addObject("results", new MagasinHelper().getClients()); mv.addObject("results", new MagasinHelper().getClientsColums());
mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate"));
break; break;
case "product": case "product":
mv.addObject("results", new MagasinHelper().getProducts()); mv.addObject("results", new MagasinHelper().getProductsColums());
mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description"));
break; break;
case "purchase": case "purchase":
mv.addObject("results", new MagasinHelper().getPurchase()); mv.addObject("results", new MagasinHelper().getPurchaseColums());
mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); mv.addObject("colonnes", Arrays.asList("orderNum", "customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany"));
mv.addObject("relation", new HashMap<String, String>() {{ mv.addObject("relation", new HashMap<String, String>() {{
put("customerId", "customer"); put("customerId", "customer");
put("productId", "product"); put("productId", "product");
@ -112,17 +112,18 @@ public class BddController extends MultiActionController {
switch (type) { switch (type) {
case "customer": case "customer":
mv.addObject("result", new MagasinHelper().getClient(Integer.parseInt(request.getParameter("num")))); mv.addObject("result", new MagasinHelper().getClient(Integer.parseInt(request.getParameter("num"))));
mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate"));
mv.addObject("code",new MagasinHelper().getDiscountCode()); mv.addObject("code",new MagasinHelper().getDiscountCode());
mv.addObject("cpostaux",new MagasinHelper().getZipCode()); mv.addObject("cpostaux",new MagasinHelper().getZipCode());
break; break;
case "product": case "product":
mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num"))));
mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); mv.addObject("manufacturers", new MagasinHelper().getManufacturers());
mv.addObject("productCodes", new MagasinHelper().getProductCodes());
break; break;
case "purchase": case "purchase":
mv.addObject("result", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("num")))); mv.addObject("result", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("num"))));
mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); mv.addObject("customers", new MagasinHelper().getClients());
mv.addObject("products", new MagasinHelper().getProducts());
break; break;
default: default:
mv.addObject("error", "Type not found"); mv.addObject("error", "Type not found");

View file

@ -56,11 +56,19 @@
</p> </p>
<p> <p>
<label for="manufacturerId">Manufacturer</label> <label for="manufacturerId">Manufacturer</label>
<input type="number" name="manufacturerId" value="${result.manufacturerId}" size="30" id="manufacturerId" /> <select name="manufacturerId" id="manufacturerId">
<c:forEach items="${manufacturers}" var="manufacturer">
<option <c:if test="${manufacturer.manufacturerId == result.manufacturerId}">selected </c:if>value="${manufacturer.manufacturerId}">${manufacturer.name}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="productCode">Product Code</label> <label for="productCode">Product Code</label>
<input type="text" name="productCode" value="${result.productCode}" size="2" id="productCode" /> <select name="productCode" id="productCode">
<c:forEach items="${productCodes}" var="productCode">
<option <c:if test="${productCode.prodCode == result.productCode}">selected </c:if>value="${productCode.prodCode}">${productCode.prodCode} - ${productCode.description}</option>
</c:forEach>
</select>
</p> </p>
<p> <p>
<label for="purchaseCost">Purchase cost</label> <label for="purchaseCost">Purchase cost</label>
@ -76,13 +84,55 @@
</p> </p>
<p> <p>
<label for="markup">Available</label> <label for="markup">Available</label>
<input type="text" name="available" value="${result.available}" id="available" size="5" /> <input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
</p> </p>
<p> <p>
<label for="description">Description</label> <label for="description">Description</label>
<input type="text" name="description" value="${result.description}" id="description" size="50" /> <input type="text" name="description" value="${result.description}" id="description" size="50" />
</p> </p>
</c:when> </c:when>
<c:when test="${type == 'purchase'}">
<p>
<label for="orderNum">Order number</label>
<input type="number" name="orderNum" value="${result.orderNum}" id="orderNum" />
</p>
<p>
<label for="customerId">Customer</label>
<select name="customerId" id="customerId">
<c:forEach items="${customers}" var="customer">
<option <c:if test="${customer.customerId == result.customerId}">selected </c:if>value="${customer.customerId}">${customer.name}</option>
</c:forEach>
</select>
</p>
<p>
<label for="productId">Product</label>
<select name="productId" id="productId">
<c:forEach items="${products}" var="product">
<option <c:if test="${product.productId == result.productId}">selected </c:if>value="${product.productId}">${product.description}</option>
</c:forEach>
</select>
</p>
<p>
<label for="quantity">Quantity</label>
<input type="number" name="quantity" value="${result.quantity}" id="quantity" />
</p>
<p>
<label for="shippingCost">Shipping cost</label>
<input type="number" name="shippingCost" value="${result.shippingCost}" id="shippingCost" />
</p>
<p>
<label for="salesDate">Sales date</label>
<input type="date" name="salesDate" value="${result.salesDate}" id="salesDate" />
</p>
<p>
<label for="shippingDate">Shipping date</label>
<input type="date" name="shippingDate" value="${result.shippingDate}" id="shippingDate" />
</p>
<p>
<label for="freightCompany">Freight company</label>
<input type="text" name="freightCompany" value="${result.freightCompany}" id="freightCompany" />
</p>
</c:when>
</c:choose> </c:choose>
<input hidden type="text" name="type" value="${type}" /> <input hidden type="text" name="type" value="${type}" />