/** * 计算总价 * * @author caijun 2014-1-6 * @param order * @return */ public static Double getOrderAmount(SalesOrder order) { Double sum = 0.0; for (int i = 0; i < order.getItems().size(); i++) { SalesOrderItem item = order.getItems().get(i); Double shl = item.getShl(); Double lshj = item.getLshj(); // 中药的价格为10g的价格,需要进行转换 if (SpkfkService.isSelfCnSp(item.getSpbh())) { lshj = lshj / SpkfkService.SELF_CN_SP_UNIT_QUANTITY; } sum = sum + shl * lshj; } return sum; }
@SuppressWarnings({"unused", "unchecked"}) @Override public Response saveOrUpdate(SalesOrder order) { Response r = new Response(); try { SalesOrder orderExist = this.getById(order.getOrderNo()); List<SalesOrderItem> itemsToDel = new ArrayList<SalesOrderItem>(); if (orderExist != null) { this.getDao().update(order); itemService.delete(orderExist.getItems()); } else { this.getDao().create(order); } for (int i = 0; i < order.getItems().size(); i++) { SalesOrderItem item = order.getItems().get(i); item.setSeq(i + 1); itemService.saveOrUpdate(item); } } catch (SQLException e) { r.setIsOk(false); r.setException(e); } return r; }
/** * 给单据加上详细信息 * * @author caijun 2014-1-6 * @param order */ private void fetchItems(SalesOrder order) { if (order != null) { List<SalesOrderItem> items = itemService.getByOrderNo(order.getOrderNo()); order.setItems(items); } }
/** * 完成单据 * * @author caijun 2014-1-6 * @param order */ public void finishOrder(SalesOrder order) { order.setState(SalesOrder.ORDER_STATE_FINISHED); order.setFinishTime(new Date()); this.saveOrUpdate(order); }