/** Create PO's */ private void createPO() { int noOrders = 0; String info = ""; // MOrder order = null; MWarehouse wh = null; X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL"); for (int i = 0; i < replenishs.length; i++) { X_T_Replenish replenish = replenishs[i]; if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID()); // if (order == null || order.getC_BPartner_ID() != replenish.getC_BPartner_ID() || order.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) { order = new MOrder(getCtx(), 0, get_TrxName()); order.setIsSOTrx(false); order.setC_DocTypeTarget_ID(p_C_DocType_ID); final MBPartner bp = new MBPartner(getCtx(), replenish.getC_BPartner_ID(), get_TrxName()); Services.get(IOrderBL.class).setBPartner(order, bp); order.setSalesRep_ID(getAD_User_ID()); order.setDescription(Msg.getMsg(getCtx(), "Replenishment")); // Set Org/WH order.setAD_Org_ID(wh.getAD_Org_ID()); order.setM_Warehouse_ID(wh.getM_Warehouse_ID()); if (!order.save()) return; log.debug(order.toString()); noOrders++; info += " - " + order.getDocumentNo(); } MOrderLine line = new MOrderLine(order); line.setM_Product_ID(replenish.getM_Product_ID()); line.setQty(replenish.getQtyToOrder()); line.setPrice(); line.save(); } m_info = "#" + noOrders + info; log.info(m_info); } // createPO
/** Create Requisition */ private void createRequisition() { int noReqs = 0; String info = ""; // MRequisition requisition = null; MWarehouse wh = null; X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL"); for (int i = 0; i < replenishs.length; i++) { X_T_Replenish replenish = replenishs[i]; if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID()); // if (requisition == null || requisition.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) { requisition = new MRequisition(getCtx(), 0, get_TrxName()); requisition.setAD_User_ID(getAD_User_ID()); requisition.setC_DocType_ID(p_C_DocType_ID); requisition.setDescription(Msg.getMsg(getCtx(), "Replenishment")); // Set Org/WH requisition.setAD_Org_ID(wh.getAD_Org_ID()); requisition.setM_Warehouse_ID(wh.getM_Warehouse_ID()); if (!requisition.save()) return; log.debug(requisition.toString()); noReqs++; info += " - " + requisition.getDocumentNo(); } // MRequisitionLine line = new MRequisitionLine(requisition); line.setM_Product_ID(replenish.getM_Product_ID()); line.setC_BPartner_ID(replenish.getC_BPartner_ID()); line.setQty(replenish.getQtyToOrder()); line.setPrice(); line.save(); } m_info = "#" + noReqs + info; log.info(m_info); } // createRequisition
/** execute the Valuation Effective Date */ protected String doIt() throws Exception { setup(); for (MWarehouse warehouse : warehouses) for (MCostType costType : costTypes) for (MCostElement costElement : costElements) generateInventoryValue( warehouse.getM_Warehouse_ID(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID()); DB.executeUpdate( "UPDATE T_InventoryValue SET cost = CASE WHEN QtyOnHand <> 0 THEN (CostAmt + CostAmtLL) / QtyOnHand ELSE 0 END , CumulatedAmt = CostAmt + CostAmtLL, DateValue = " + DB.TO_DATE(p_DateValue) + " WHERE AD_PInstance_ID=?", getAD_PInstance_ID(), get_TrxName()); return "@Ok@"; }
/** Create Inventory Movements */ private void createMovements() { int noMoves = 0; String info = ""; // MClient client = null; MMovement move = null; int M_Warehouse_ID = 0; int M_WarehouseSource_ID = 0; MWarehouse whSource = null; MWarehouse wh = null; X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL"); for (int i = 0; i < replenishs.length; i++) { X_T_Replenish replenish = replenishs[i]; if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID()) whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID()); if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID()); if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID()) client = MClient.get(getCtx(), whSource.getAD_Client_ID()); // if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) { M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID(); M_Warehouse_ID = replenish.getM_Warehouse_ID(); move = new MMovement(getCtx(), 0, get_TrxName()); move.setC_DocType_ID(p_C_DocType_ID); move.setDescription( Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName()); // Set Org move.setAD_Org_ID(whSource.getAD_Org_ID()); if (!move.save()) return; log.debug(move.toString()); noMoves++; info += " - " + move.getDocumentNo(); } // To int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID(); // From: Look-up Storage MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID()); String MMPolicy = product.getMMPolicy(); MStorage[] storages = MStorage.getWarehouse( getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName()); // BigDecimal target = replenish.getQtyToOrder(); for (int j = 0; j < storages.length; j++) { MStorage storage = storages[j]; if (storage.getQtyOnHand().signum() <= 0) continue; BigDecimal moveQty = target; if (storage.getQtyOnHand().compareTo(moveQty) < 0) moveQty = storage.getQtyOnHand(); // MMovementLine line = new MMovementLine(move); line.setM_Product_ID(replenish.getM_Product_ID()); line.setMovementQty(moveQty); if (replenish.getQtyToOrder().compareTo(moveQty) != 0) line.setDescription("Total: " + replenish.getQtyToOrder()); line.setM_Locator_ID(storage.getM_Locator_ID()); // from line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID()); line.setM_LocatorTo_ID(M_LocatorTo_ID); // to line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID()); line.save(); // target = target.subtract(moveQty); if (target.signum() == 0) break; } } if (replenishs.length == 0) { m_info = "No Source Warehouse"; log.warn(m_info); } else { m_info = "#" + noMoves + info; log.info(m_info); } } // createRequisition
public String readFile() throws IOException { File inputWorkbook = new File(archivo); Workbook w; try { String msg = ""; w = Workbook.getWorkbook(inputWorkbook); // Get the first sheet Sheet sheet = w.getSheet(0); // int defaultRows = sheet.getRows(); // Si la cantidad de columnas es 4 if (sheet.getColumns() >= 4 && sheet.getRows() > 1) { // Valido que las cabeceras tengan el formato correcto if (!sheet.getCell(0, 0).getContents().equals("ORIGEN") || !sheet.getCell(1, 0).getContents().equals("DESTINO") || !sheet.getCell(2, 0).getContents().equals("PRODUCTO") || !sheet.getCell(3, 0).getContents().equals("PIEZAS")) { msg = Msg.translate(getCtx(), "Column Names"); return msg; } // El vector que almacena la estructura de traspasos Vector<Movimiento> movimientos = new Vector<Movimiento>(); Iterator<Movimiento> iterator_movimientos = null; Movimiento movimiento_temporal = null, movimiento_nuevo = null; for (int i = 1; i < sheet.getRows() && getStore(sheet.getCell(0, i).getContents()) != null; i++) { // Capturo el origen MWarehouse origen = getStore(sheet.getCell(0, i).getContents()); MWarehouse destino = getStore(sheet.getCell(1, i).getContents()); String isStore = "N"; // Aca debo bucar los values de los m_warehouse que son cd String sql = "SELECT XX_IsStore FROM M_Warehouse WHERE M_Warehouse_ID in ( " + origen.getM_Warehouse_ID() + "," + destino.getM_Warehouse_ID() + ")"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); rs = pstmt.executeQuery(); while (rs.next()) { if (rs.getString(1).equals("Y")) isStore = rs.getString(1); } } catch (Exception a) { log.log(Level.SEVERE, sql, a); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } if (origen == null || isStore.equals("Y")) return Msg.translate(getCtx(), "Cell A Error") + (i + 1) + " " + sheet.getCell(0, i).getContents(); // Capturo el destino if (destino == null || isStore.equals("Y")) return Msg.translate(getCtx(), "Cell B Error") + (i + 1) + " " + sheet.getCell(1, i).getContents(); // Capturo el producto String p_id = sheet.getCell(2, i).getContents(); MProduct producto = getProduct(p_id); if (producto == null) { return Msg.translate(getCtx(), "Cell C Error") + (i + 1) + " " + sheet.getCell(2, i).getContents(); } // Capturo las piezas Double piezas = null; try { if (sheet.getCell(3, i) != null) piezas = Double.parseDouble(sheet.getCell(3, i).getContents()); } catch (NumberFormatException e) { return Msg.translate(getCtx(), "Cell D Error") + (i + 1) + " " + sheet.getCell(3, i).getContents(); } if (piezas == null) { return Msg.translate(getCtx(), "Cell D Error") + (i + 1) + " " + sheet.getCell(3, i).getContents(); } // Agregar cada fila al vector de traspasos iterator_movimientos = movimientos.iterator(); boolean encontrado = false; while (iterator_movimientos.hasNext()) { movimiento_temporal = iterator_movimientos.next(); // Si un traspaso anterior va a la misma tienda, departamento, etc if (movimiento_temporal.origen == origen.get_ID()) { if (movimiento_temporal.destino == destino.get_ID()) { if (movimiento_temporal.departamento == producto.getXX_VMR_Department_ID()) { // Entonces agregar algo al objeto traspaso movimiento_temporal.agregarCantidades(producto.get_ID(), piezas); encontrado = true; break; } } } } // Si no se encontró en el vector de traspasos agregarlo if (!encontrado) { movimiento_nuevo = new Movimiento( origen.get_ID(), destino.get_ID(), producto.getXX_VMR_Department_ID()); movimiento_nuevo.agregarCantidades(producto.get_ID(), piezas); movimientos.add(movimiento_nuevo); } } // Una vez leido todo el archivo se procede a crear los traspasos // System.out.println(traspasos); return procesarMovimientos(movimientos).toString(); } else { return Msg.translate(getCtx(), "4 Columns"); } } catch (BiffException e) { log.log(Level.SEVERE, e.getMessage()); } return ""; }