public void addOrderLine(String productName, Long amount) { OrderLine orderLine = new OrderLine(); orderLine.setProductName(productName); orderLine.setAmount(amount); this.orderLines.add(orderLine); }
public static Set<Category> getDistinctCategories(Order order) { Set<Category> catSet = new HashSet<Category>(); for (OrderLine line : order.getOrderLines()) { catSet.add(line.getItem().getProduct().getCategory()); } return catSet; }
@Test public void testClassBridgeInstanceMapping() throws Exception { OrderLine orderLine = new OrderLine(); orderLine.setName("Sequoia"); FullTextSession s = Search.getFullTextSession(openSession()); Transaction tx = s.beginTransaction(); s.persist(orderLine); tx.commit(); s.clear(); tx = s.beginTransaction(); QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer); org.apache.lucene.search.Query luceneQuery = parser.parse("orderLineName:Sequoia"); FullTextQuery query = s.createFullTextQuery(luceneQuery); assertEquals("Bridge not used", 1, query.getResultSize()); luceneQuery = parser.parse("orderLineName_ngram:quo"); query = s.createFullTextQuery(luceneQuery); assertEquals("Analyzer configuration not applied", 1, query.getResultSize()); luceneQuery = parser.parse("orderLineNameViaParam:Sequoia"); query = s.createFullTextQuery(luceneQuery); assertEquals("Parameter configuration not applied", 1, query.getResultSize()); s.delete(query.list().get(0)); tx.commit(); s.close(); }
public Float getTotal() { if (orderLines == null || orderLines.isEmpty()) return 0f; Float total = 0f; // sum up the quantities for (OrderLine orderLine : orderLines) { total += (orderLine.getSubTotal()); } return total; }
@Override public long apply(OrderLine orderLine) { // Compare Discount.productID with orderLine.productID // If true return reduced price otherwise return normal price int productAmount = orderLine.getProductQuantity(); long productPrice = orderLine.getProductPrice(); if (itemIDs.contains(orderLine.getProductID())) productAmount -= (productAmount / requiredQuantity) * reductionQuantity; return productAmount * productPrice; }
// Update the argument Map, adding the amounts for each book that this client ever ordered public void updateQuantityOfBooksOrdered(Map<Book, Integer> quantities) { for (Orders order : getOrders()) { for (OrderLine orderLine : order.getOrderLines()) { Book book = orderLine.getBook(); Integer quantity = quantities.get(book); if (quantity == null) { quantity = orderLine.getQty(); } else { quantity += orderLine.getQty(); } quantities.put(book, quantity); } } }
public void doWork(Session session) throws Exception { XorShiftRandom rng = new XorShiftRandom(seeder.nextInt()); Order order = new Order(); session.persist(order); for (int i = 0; i < 10; i++) { int productId = rng.nextInt() & 1023; Product product = (Product) session.get(Product.class, productId); OrderLine orderLine = new OrderLine(); orderLine.setOrder(order); orderLine.setProduct(product); session.persist(orderLine); order.getOrderLines().add(orderLine); } }
@Override public void export( String path, Vector<OrderLine> orderLines, String codeJournal, Account documentAccount) throws IOException { int total = 0; String number = (documentAccount == null) ? "" : documentAccount.getNumber(); OrderLine e = null; PrintWriter out = new PrintWriter(new FileWriter(path)); for (int i = 0, n = orderLines.size(); i < n; i++) { e = orderLines.elementAt(i); total += e.getAmount(); // String f = (AccountUtil.isPersonalAccount(e.getAccount()) && e.getInvoice() != null) ? // e.getInvoice() : e.getInvoiceNumber(); // out.print(padWithTrailingZeros(e.getAccount().getNumber(), 10) out.print( TextUtil.padWithTrailingZeros(getAccount(e), 10) + "#" + dateFormat.format(e.getDate().getDate()) + "#" + codeJournal + "#" + TextUtil.padWithTrailingSpaces(e.getDocument(), 10) // La valeur 13 ne semble pas obligatoire. On peut étendre la taille du champ. // + "#" + padWithTrailingSpaces(truncate(e.getLabel(), 13), 13) + "#" + TextUtil.padWithTrailingSpaces( TextUtil.truncate(e.getLabel() + getInvoiceNumber(e), 24), 24) // numéro de facture pour les echéances correspondant à une facture. + "#" + TextUtil.padWithLeadingZeros(nf.format(e.getAmount() / 100.0), 13) + "#" + cd + "#" + TextUtil.padWithTrailingSpaces(e.getCostAccount().getNumber(), 10) + "#" + (char) 13); } if (total > 0) { out.print( TextUtil.padWithTrailingZeros(number, 10) + "#" + dateFormat.format(e.getDate().getDate()) + "#" + codeJournal + "#" + TextUtil.padWithTrailingSpaces("", 10) + "#" + TextUtil.padWithTrailingSpaces("CENTRALISE", 24) + "#" + TextUtil.padWithLeadingZeros(nf.format(total / 100.0), 13) + "#" + dc + "#" + TextUtil.padWithTrailingSpaces("", 10) + "#" + (char) 13); // CR (Carriage return, retour à la ligne) } out.close(); }
public void doWork(Session session) throws Exception { @SuppressWarnings("unchecked") List<Order> chargedOrders = session.createCriteria(Order.class).add(Restrictions.eq("state", 2)).list(); for (Order order : chargedOrders) { order.setState(3); for (OrderLine orderLine : order.getOrderLines()) { Product product = orderLine.getProduct(); product.setQuantity(product.getQuantity() - 1); session.update(product); } session.update(order); } }
public void doWork(Session session) throws Exception { @SuppressWarnings("unchecked") List<Order> pendingOrders = session.createCriteria(Order.class).add(Restrictions.eq("state", 1)).list(); for (Order order : pendingOrders) { order.setState(2); int charge = 0; for (OrderLine orderLine : order.getOrderLines()) { charge += orderLine.getProduct().getPrice(); } order.setCharge(charge); session.update(order); } }
public ElectronicFulfilmentRequest createElectronicFulfilmentRequest( OrderLineSetId setDetails, Set<OrderLine> orderLines, CanonicalOrder order, String electronicFulfilmentRequestId) { linkedOrderLineMap = new HashMap<String, LinkedOrderLine>(); orderLineMap = new HashMap<String, CanonicalOLI>(); parentLinkedOrderLines = new HashSet<String>(); // Create a map of all order lines for (CanonicalOLI orderLine : order.getOrderLineItem()) { // Add the order line to a HashMap for easy lookup by Order Line ID orderLineMap.put(orderLine.getCRMOLIId(), orderLine); } logger.log(Level.FINEST, "orderLineMap created with size=" + orderLineMap.size()); // Create a tree of Linked Order Lines for (OrderLine orderLine : orderLines) { // Add the order line to a HashMap for easy lookup by Order Line ID addOrderLinetoLinkedOrderLineMap( new LinkedOrderLine(orderLineMap.get(orderLine.getOrderLineId()))); } logger.log(Level.FINEST, "linkedOrderLineMap created with size=" + linkedOrderLineMap.size()); logger.log( Level.FINEST, "parentLinkedOrderLines created with size=" + parentLinkedOrderLines.size()); /* Now construct the electronic fulfilment request * */ ElectronicFulfilmentRequest electronicFulfilmentRequest = new ElectronicFulfilmentRequest(); electronicFulfilmentRequest.setElectronicFulfilmentRequestId(electronicFulfilmentRequestId); electronicFulfilmentRequest.setSubscriberAccount(setDetails.getSubscriber()); electronicFulfilmentRequest.setUUID(setDetails.getUuid()); electronicFulfilmentRequest.setModifyUserEntitlements(new ModifyUserEntitlements()); List<Entitlement> entitlements = new Vector<Entitlement>(); for (String linkedOrderLineId : parentLinkedOrderLines) { entitlements.add(createEntitlement(linkedOrderLineMap.get(linkedOrderLineId))); } electronicFulfilmentRequest .getModifyUserEntitlements() .setEntitlement(entitlements.toArray(new Entitlement[entitlements.size()])); return electronicFulfilmentRequest; }
@Override protected boolean beforeAddOrderLine(OrderLine orderLine) { // Si la línea de pedido ya está asociada con alguna línea del remito entonces // no debe ser mostrada en la grilla. No se permite que dos líneas de un mismo // remito compartan una línea del pedido. String sql = "SELECT COUNT(*) FROM M_InOutLine WHERE M_InOut_ID = ? AND C_OrderLine_ID = ?"; Long count = (Long) DB.getSQLObject( null, sql, new Object[] {getInOut().getM_InOut_ID(), orderLine.orderLineID}); if (count != null && count > 0) { return false; } // Para devoluciones de clientes, la cantidad pendiente es en realidad // la cantidad que se le ha entregado. if ((isSOTrx() && getInOut().getMovementType().endsWith("+")) || (!isSOTrx() && getInOut().getMovementType().endsWith("-"))) { orderLine.remainingQty = orderLine.qtyDelivered; } return true; }
public double getTotalPrice() { for (OrderLine ol : orderlines) { this.order_price = this.order_price + ol.computePrice(); } return this.order_price; }
@Override public int tiersExport(String path, Vector<OrderLine> orderLines) throws IOException, SQLException { // OrderLine e = null; int errors = 0; boolean m1 = false; boolean m2 = false; String message = ""; StringBuilder logMessage = new StringBuilder(); String m1prefix = MessageUtil.getMessage("account.error"); String m2prefix = MessageUtil.getMessage("matching.account.error"); String logpath = path + ".log"; PrintWriter out = new PrintWriter(new FileWriter(path)); for (int i = 0, n = orderLines.size(); i < n; i++) { e = orderLines.elementAt(i); if (!AccountUtil.isPersonalAccount(e.getAccount())) { errors++; logMessage .append(m1prefix) .append(" -> ") .append(e) .append(" [") .append(e.getAccount()) .append("]") .append(TextUtil.LINE_SEPARATOR); m1 = true; continue; } int p = getPersonalAccountId(e.getAccount().getId()); if (p == 0) { errors++; logMessage .append(m2prefix) .append(" -> ") .append(e.getAccount()) .append(TextUtil.LINE_SEPARATOR); m2 = true; continue; } Account c = getAccount(p); String m = nf.format(Math.abs(e.getAmount()) / 100.0); // le montant doit être positif String codeJournal = getCodeJournal(e.getAccount().getId()); String f = (e.getInvoice() == null) ? "" : e.getInvoice(); out.print( TextUtil.padWithTrailingZeros(c.getNumber(), 10) + "#" + dateFormat.format(e.getDate().getDate()) + "#" + codeJournal + "#" + TextUtil.padWithTrailingSpaces(e.getDocument(), 10) + "#" + TextUtil.padWithTrailingSpaces(TextUtil.truncate(e.getLabel(), 24), 24) + "#" + TextUtil.padWithLeadingZeros(m, 13) + "#" + (e.getAmount() < 0 ? cd : dc) // cd Crédit + "#" + TextUtil.padWithTrailingSpaces(e.getCostAccount().getNumber(), 10) + "#" + (char) 13); out.print( TextUtil.padWithTrailingZeros(getAccount(e), 10) // compte client + "#" + dateFormat.format(e.getDate().getDate()) + "#" + codeJournal + "#" + TextUtil.padWithTrailingSpaces(f, 10) + "#" + TextUtil.padWithTrailingSpaces(TextUtil.truncate(e.getLabel(), 24), 24) + "#" + TextUtil.padWithLeadingZeros(m, 13) + "#" + (e.getAmount() < 0 ? dc : cd) // dc Débit + "#" + TextUtil.padWithTrailingSpaces("", 10) + "#" + (char) 13); // CR (Carriage return, retour à la ligne) } out.close(); if (logMessage.length() > 0) { PrintWriter log = new PrintWriter(new FileWriter(logpath)); log.println(logMessage.toString()); log.close(); } if (errors > 0) { if (m1) { message += MessageUtil.getMessage("personal.account.export.warning"); } if (m2) { message += MessageUtil.getMessage("no.revenue.matching.warning"); } String err = MessageUtil.getMessage("error.count.warning", errors); String l = MessageUtil.getMessage("see.log.file", path); MessagePopup.warning(null, err + message + l); } return errors; }
static int loadOrder(int whseKount, int distWhseKount, int custDistKount) { int k = 0; int t = 0; PrintWriter outLine = null; PrintWriter outNewOrder = null; try { if (outputFiles == true) { out = new PrintWriter(new FileOutputStream(fileLocation + "order.csv")); System.out.println("\nWriting Order file to: " + fileLocation + "order.csv"); outLine = new PrintWriter(new FileOutputStream(fileLocation + "order-line.csv")); System.out.println("\nWriting Order Line file to: " + fileLocation + "order-line.csv"); outNewOrder = new PrintWriter(new FileOutputStream(fileLocation + "new-order.csv")); System.out.println("\nWriting New Order file to: " + fileLocation + "new-order.csv"); } now = new java.util.Date(); Oorder oorder = new Oorder(); NewOrder new_order = new NewOrder(); OrderLine order_line = new OrderLine(); jdbcIO myJdbcIO = new jdbcIO(); t = (whseKount * distWhseKount * custDistKount); t = (t * 11) + (t / 3); System.out.println( "whse=" + whseKount + ", dist=" + distWhseKount + ", cust=" + custDistKount); System.out.println("\nStart Order-Line-New Load for approx " + t + " rows @ " + now + " ..."); for (int w = 1; w <= whseKount; w++) { for (int d = 1; d <= distWhseKount; d++) { for (int c = 1; c <= custDistKount; c++) { oorder.o_id = c; oorder.o_w_id = w; oorder.o_d_id = d; oorder.o_c_id = jTPCCUtil.randomNumber(1, custDistKount, gen); oorder.o_carrier_id = jTPCCUtil.randomNumber(1, 10, gen); oorder.o_ol_cnt = jTPCCUtil.randomNumber(5, 15, gen); oorder.o_all_local = 1; oorder.o_entry_d = System.currentTimeMillis(); k++; if (outputFiles == false) { myJdbcIO.insertOrder(ordrPrepStmt, oorder); } else { String str = ""; str = str + oorder.o_id + ","; str = str + oorder.o_w_id + ","; str = str + oorder.o_d_id + ","; str = str + oorder.o_c_id + ","; str = str + oorder.o_carrier_id + ","; str = str + oorder.o_ol_cnt + ","; str = str + oorder.o_all_local + ","; Timestamp entry_d = new java.sql.Timestamp(oorder.o_entry_d); str = str + entry_d; out.println(str); } // 900 rows in the NEW-ORDER table corresponding to the last // 900 rows in the ORDER table for that district (i.e., with // NO_O_ID between 2,101 and 3,000) if (c > 2100) { new_order.no_w_id = w; new_order.no_d_id = d; new_order.no_o_id = c; k++; if (outputFiles == false) { myJdbcIO.insertNewOrder(nworPrepStmt, new_order); } else { String str = ""; str = str + new_order.no_w_id + ","; str = str + new_order.no_d_id + ","; str = str + new_order.no_o_id; outNewOrder.println(str); } } // end new order for (int l = 1; l <= oorder.o_ol_cnt; l++) { order_line.ol_w_id = w; order_line.ol_d_id = d; order_line.ol_o_id = c; order_line.ol_number = l; // ol_number order_line.ol_i_id = jTPCCUtil.randomNumber(1, 100000, gen); order_line.ol_delivery_d = oorder.o_entry_d; if (order_line.ol_o_id < 2101) { order_line.ol_amount = 0; } else { // random within [0.01 .. 9,999.99] float f = (float) (jTPCCUtil.randomNumber(1, 999999, gen) / 100.0); order_line.ol_amount = f; // XXX float error line 1. } order_line.ol_supply_w_id = jTPCCUtil.randomNumber(1, numWarehouses, gen); order_line.ol_quantity = 5; order_line.ol_dist_info = jTPCCUtil.randomStr(24); k++; if (outputFiles == false) { myJdbcIO.insertOrderLine(orlnPrepStmt, order_line); } else { String str = ""; str = str + order_line.ol_w_id + ","; str = str + order_line.ol_d_id + ","; str = str + order_line.ol_o_id + ","; str = str + order_line.ol_number + ","; str = str + order_line.ol_i_id + ","; Timestamp delivery_d = new Timestamp(order_line.ol_delivery_d); str = str + delivery_d + ","; str = str + order_line.ol_amount + ","; str = str + order_line.ol_supply_w_id + ","; str = str + order_line.ol_quantity + ","; str = str + order_line.ol_dist_info; outLine.println(str); } if ((k % configCommitCount) == 0) { long tmpTime = new java.util.Date().getTime(); String etStr = " Elasped Time(ms): " + ((tmpTime - lastTimeMS) / 1000.000) + " "; System.out.println(etStr.substring(0, 30) + " Writing record " + k + " of " + t); lastTimeMS = tmpTime; if (outputFiles == false) { ordrPrepStmt.executeBatch(); nworPrepStmt.executeBatch(); orlnPrepStmt.executeBatch(); ordrPrepStmt.clearBatch(); nworPrepStmt.clearBatch(); orlnPrepStmt.clearBatch(); transCommit(); } } } // end for [l] } // end for [c] } // end for [d] } // end for [w] System.out.println(" Writing final records " + k + " of " + t); if (outputFiles == false) { ordrPrepStmt.executeBatch(); nworPrepStmt.executeBatch(); orlnPrepStmt.executeBatch(); } else { outLine.close(); outNewOrder.close(); } transCommit(); now = new java.util.Date(); System.out.println("End Orders Load @ " + now); } catch (Exception e) { e.printStackTrace(); transRollback(); if (outputFiles == true) { outLine.close(); outNewOrder.close(); } } return (k); } // end loadOrder()
public boolean isDiscounted(OrderLine orderLine) { if (orderLine.getProductQuantity() >= requiredQuantity) return super.isDiscounted(orderLine); return false; }
/** Add the order line to the order, and set the back reference and update the order cost. */ public void addOrderLine(OrderLine orderLine) { getOrderLines().add(orderLine); orderLine.setLineNumber(getOrderLines().size()); setTotalCost(getTotalCost() + orderLine.getCost()); }