/** Envia correos al personal de tienda en caso de la aprobación de un traspaso */ private void enviarCorreoATienda(MMovement movimiento, int plantillaDeCorreo) { MWarehouse almaSalida = new MWarehouse(getCtx(), movimiento.getM_WarehouseFrom_ID(), null); MWarehouse almaLleada = new MWarehouse(getCtx(), movimiento.getM_WarehouseTo_ID(), null); X_XX_VMR_Department departamento = new X_XX_VMR_Department(getCtx(), movimiento.getXX_VMR_Department_ID(), null); // Mensaje debe indicar departamento, origen, destino y traspaso String mensaje = Msg.getMsg( getCtx(), "XX_PTransferApproval", new String[] { movimiento.getDocumentNo(), departamento.getValue() + "-" + departamento.getName(), almaSalida.getValue() + "-" + almaSalida.getName(), almaLleada.getValue() + "-" + almaLleada.getName(), movimiento.getXX_StatusName() }); // Al Gerente de Tienda // Selecciono el o los gerentes de Tienda String SQL = "SELECT AD_USER_ID FROM AD_USER WHERE ISACTIVE='Y' " + " AND C_BPARTNER_ID IN " + "(" + "SELECT C_BPARTNER_ID " + "FROM C_BPARTNER WHERE isActive='Y' " + "AND C_JOB_ID =" + Env.getCtx().getContextAsInt("#XX_L_JOBPOSITION_STOREMAN_ID") + " " + "AND (M_WAREHOUSE_ID = " + almaLleada.get_ID() + " " + "OR M_WAREHOUSE_ID = " + almaSalida.get_ID() + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")" + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")"; Vector<Integer> storeManagers = new Vector<Integer>(); try { PreparedStatement pstmt = DB.prepareStatement(SQL, null); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { storeManagers.add(rs.getInt("AD_USER_ID")); } rs.close(); pstmt.close(); } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } // Envio correos a los gerentes Utilities f = null; for (int i = 0; i < storeManagers.size(); i++) { f = new Utilities( Env.getCtx(), null, plantillaDeCorreo, mensaje, -1, Env.getCtx().getContextAsInt("#XX_L_USERFROMMAIL_ID"), -1, storeManagers.get(i), null); try { f.ejecutarMail(); } catch (Exception e) { e.printStackTrace(); } f = null; } // ********************************* // Selecciono los asesores de almacen SQL = "SELECT AD_USER_ID FROM AD_USER WHERE ISACTIVE='Y' " + "AND C_BPARTNER_ID IN " + "(" + "SELECT C_BPARTNER_ID FROM C_BPARTNER WHERE isActive='Y' " + "AND C_JOB_ID =" + Env.getCtx().getContextAsInt("#XX_L_JOBPOSITION_DEPASE_ID") + " " + "AND (M_WAREHOUSE_ID = " + almaLleada.get_ID() + " " + "OR M_WAREHOUSE_ID = " + almaSalida.get_ID() + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")" + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")"; Vector<Integer> warehouseAsessors = new Vector<Integer>(); try { PreparedStatement pstmt = DB.prepareStatement(SQL, null); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { warehouseAsessors.add(rs.getInt("AD_USER_ID")); } rs.close(); pstmt.close(); } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } // Envio correos a los asesores Utilities m = null; for (int i = 0; i < warehouseAsessors.size(); i++) { m = new Utilities( Env.getCtx(), null, plantillaDeCorreo, mensaje, -1, Env.getCtx().getContextAsInt("#XX_L_USERFROMMAIL_ID"), -1, warehouseAsessors.get(i), null); try { m.ejecutarMail(); } catch (Exception e) { e.printStackTrace(); } m = null; } // ********************************* // Selecciono los Gerentes de Area ADMIN y MERCA, Asesor de Inventario SQL = "SELECT AD_USER_ID FROM AD_USER WHERE ISACTIVE='Y' " + "AND C_BPARTNER_ID IN " + "(" + "SELECT C_BPARTNER_ID FROM C_BPARTNER WHERE isActive='Y' " + "AND C_JOB_ID IN (" + " " + Env.getCtx().getContextAsInt("#XX_L_JOBPOSITION_ADMINMANAG_ID") + "," + " " + Env.getCtx().getContextAsInt("#XX_L_JOBPOSITION_GAMERC_ID") + "," + " " + Env.getCtx().getContextAsInt("#XX_L_JOBPOSITION_INVASSES_ID") + ") " + "AND (M_WAREHOUSE_ID = " + almaLleada.get_ID() + " " + "OR M_WAREHOUSE_ID = " + almaSalida.get_ID() + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")" + ") " + "AND AD_Client_ID IN (0," + Env.getCtx().getAD_Client_ID() + ")"; Vector<Integer> managerArea = new Vector<Integer>(); try { PreparedStatement pstmt = DB.prepareStatement(SQL, null); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { managerArea.add(rs.getInt("AD_USER_ID")); } rs.close(); pstmt.close(); } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } // Envio correos a gerentes de area Utilities u = null; for (int i = 0; i < managerArea.size(); i++) { u = new Utilities( Env.getCtx(), null, plantillaDeCorreo, mensaje, -1, Env.getCtx().getContextAsInt("#XX_L_USERFROMMAIL_ID"), -1, managerArea.get(i), null); try { u.ejecutarMail(); } catch (Exception e) { e.printStackTrace(); } u = null; } }
private void fillProductTable() { int row = 0; try { String get_details = " SELECT XX_VMR_DiscountAppliDetail_ID FROM XX_VMR_DiscountAppliDetail " + " WHERE XX_VMR_DiscountRequest_ID = " + header.get_ID(); PreparedStatement pstmt = DB.prepareStatement(get_details, null); // Setting the query parameters ResultSet rs = pstmt.executeQuery(); while (rs.next()) { row = xProductTable.getRowCount(); xProductTable.setRowCount(row + 1); MVMRDiscountAppliDetail detail = new MVMRDiscountAppliDetail(Env.getCtx(), rs.getInt(1), null); IDColumn id = new IDColumn(rs.getInt(1)); id.setSelected(true); xProductTable.setValueAt(id, row, 0); MProduct prod = new MProduct(Env.getCtx(), detail.getM_Product_ID(), null); xProductTable.setValueAt(new KeyNamePair(prod.get_ID(), prod.getValue()), row, 1); xProductTable.setValueAt(prod.getKeyNamePair(), row, 3); X_XX_VMR_VendorProdRef ref_proveedor = new X_XX_VMR_VendorProdRef(Env.getCtx(), prod.getXX_VMR_VendorProdRef_ID(), null); xProductTable.setValueAt( new KeyNamePair(ref_proveedor.get_ID(), ref_proveedor.getValue()), row, 2); // Colocar el consecutivo de precio DecimalFormat formato = new DecimalFormat("000"); X_XX_VMR_PriceConsecutive priceConsecutive = new X_XX_VMR_PriceConsecutive(Env.getCtx(), detail.getXX_PriceConsecutive_ID(), null); xProductTable.setValueAt(formato.format(priceConsecutive.getXX_PriceConsecutive()), row, 4); xProductTable.setValueAt(detail.getXX_LoweringQuantity(), row, 5); xProductTable.setValueAt(detail.getXX_LoweringQuantity(), row, 6); X_XX_VMR_Category cat = new X_XX_VMR_Category(Env.getCtx(), prod.getXX_VMR_Category_ID(), null); xProductTable.setValueAt(cat.getKeyNamePair(), row, 7); X_XX_VMR_Department dep = new X_XX_VMR_Department(Env.getCtx(), header.getXX_VMR_Department_ID(), null); xProductTable.setValueAt(dep.getKeyNamePair(), row, 8); X_XX_VMR_Line lin = new X_XX_VMR_Line(Env.getCtx(), detail.getXX_VMR_Line_ID(), null); xProductTable.setValueAt(lin.getKeyNamePair(), row, 9); X_XX_VMR_Section sec = new X_XX_VMR_Section(Env.getCtx(), detail.getXX_VMR_Section_ID(), null); xProductTable.setValueAt(sec.getKeyNamePair(), row, 10); if (priceConsecutive.getM_AttributeSetInstance_ID() != 0) { MAttributeSetInstance attins = new MAttributeSetInstance( Env.getCtx(), priceConsecutive.getM_AttributeSetInstance_ID(), null); xProductTable.setValueAt( new KeyNamePair(attins.get_ID(), attins.getDescription()), row, 11); } else { xProductTable.setValueAt(new KeyNamePair(0, ""), row, 11); } } rs.close(); pstmt.close(); } catch (Exception E) { E.printStackTrace(); } }
public void print_labels(PrintService psZebra, int row, boolean glued) { try { IDColumn column = (IDColumn) xProductTable.getValueAt(row, 0); KeyNamePair knp_product = (KeyNamePair) xProductTable.getValueAt(row, 3); KeyNamePair knp_att = (KeyNamePair) xProductTable.getValueAt(row, 11); MVMRDiscountAppliDetail detail = new MVMRDiscountAppliDetail(Env.getCtx(), column.getRecord_ID(), null); int cantidadEtiquetas = ((Number) xProductTable.getValueAt(row, 6)).intValue(); MProduct producto = new MProduct(Env.getCtx(), knp_product.getKey(), null); String name = producto.getName(); /* * Caracteristica larga * */ X_XX_VMR_LongCharacteristic caracLarga = new X_XX_VMR_LongCharacteristic( Env.getCtx(), producto.getXX_VMR_LongCharacteristic_ID(), null); X_M_AttributeSet attrSet = new X_M_AttributeSet(Env.getCtx(), producto.getM_AttributeSet_ID(), null); DecimalFormat formato = new DecimalFormat(".##"); // String attr = "AMARILLO T=G "; // "CHEMISE CABALLERO " X_XX_VMR_Department dep = new X_XX_VMR_Department(Env.getCtx(), producto.getXX_VMR_Department_ID(), null); String departmentCode = dep.getValue(); X_XX_VMR_Line lin = new X_XX_VMR_Line(Env.getCtx(), producto.getXX_VMR_Line_ID(), null); String lineCode = lin.getValue(); X_XX_VMR_Section sec = new X_XX_VMR_Section(Env.getCtx(), producto.getXX_VMR_Section_ID(), null); String seccionCode = sec.getValue(); String precio = formato.format(detail.getXX_PriceBeforeDiscount()); MVMRDiscountRequest headerDiscount = new MVMRDiscountRequest(Env.getCtx(), detail.getXX_VMR_DiscountRequest_ID(), null); MWarehouse tienda = new MWarehouse(Env.getCtx(), headerDiscount.getM_Warehouse_ID(), null); X_XX_VMR_PriceConsecutive consecutivoViejo = new X_XX_VMR_PriceConsecutive(Env.getCtx(), detail.getXX_VMR_PriceConsecutive_ID(), null); // Debo buscar semana, mes y año de la fecha de creacion del consecutivo Date date = (Date) consecutivoViejo.getCreated(); Calendar cal = new GregorianCalendar(); cal.setTime(date); int mes = cal.get(Calendar.MONTH) + 1; int año = cal.get(Calendar.YEAR); int semana = cal.get(Calendar.WEEK_OF_YEAR); BigDecimal impuesto = new BigDecimal(0); if (producto.getC_TaxCategory_ID() != 0) { String sql_rate = " SELECT (RATE) FROM C_TAX " + " WHERE C_TaxCategory_ID= " + producto.getC_TaxCategory_ID() + " AND ValidFrom <= to_date('" + date.toString().substring(0, 10) + "','yyyy-mm-dd')" + " and rownum = 1 " + " order by ValidFrom desc "; try { PreparedStatement prst_tax = DB.prepareStatement(sql_rate, null); ResultSet rs_tax = prst_tax.executeQuery(); if (rs_tax.next()) { impuesto = rs_tax.getBigDecimal(1).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); } rs_tax.close(); prst_tax.close(); } catch (Exception e) { System.out.println("error al calcular el impuesto"); } } String product_plus_correlative = "" + producto.getValue() + consecutivoTostring(consecutivoViejo.getXX_PriceConsecutive()); String s = ""; DocPrintJob job = psZebra.createPrintJob(); if (impuesto.compareTo(new BigDecimal(0)) > 0) { precio = formato.format( (detail .getXX_PriceBeforeDiscount() .add((detail.getXX_PriceBeforeDiscount()).multiply(impuesto))) .setScale(2, BigDecimal.ROUND_HALF_UP)); s = "^XA^PRD^XZ\n" + "^XA^JMA^\n" + "^LH07,02^FS\n" + "^FO10,03^BE,25,N^BY3, 0.5,45^FD" + product_plus_correlative + "^FS\n" + "^FO10,62^AA,15,12^FD" + departmentCode + "-" + lineCode + "-" + seccionCode + "-" + product_plus_correlative + " ^FS\n" + "^FO10,82^AA,20,10^FD" + name + "^FS\n"; if (!attrSet.getName().isEmpty() && attrSet.get_ID() != Env.getCtx().getContextAsInt("#XX_L_P_ATTRIBUTESETST_ID")) { s = s + "^FO10,97^AA,20,10^FD" + (attrSet.getName().length() > 30 ? attrSet.getName().substring(0, 29) : attrSet.getName()) + "^FS\n"; } else if (caracLarga != null && caracLarga.getName() != null && !caracLarga.getName().isEmpty()) { s = s + "^FO10,97^AA,20,10^FD" + (caracLarga.getName().length() > 30 ? caracLarga.getName().substring(0, 29) : caracLarga.getName()) + "^FS\n"; } s = s + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n" + "^FO10,170^AB,11,07^FDRIF J-00046517-7 Incluye IVA " + impuesto.multiply(new BigDecimal(100)) + "%^FS\n" + "^FO10,153^AB,11,07^CI10^FD" + semana + " " + mes + " " + año + "^FS\n" + "^FO10,138^AA,11,09^FDBsF.^FS\n" + "^FO35,136^AB,11,07^CI10^FD " + precio + "^FS\n" + "^PQ" + cantidadEtiquetas + "^FS\n" + "^XZ\n" + // Control label "^XA^PRD^XZ\n" + "^XA^JMA^\n" + "^LH00,15^FS\n" + "^FO2,5^AD,38,10^FD*CONTROL* " + semana + " " + mes + "" + año + "^FS\n" + "^FO05,45^A0,30,07^FD TDA: " + tienda.getValue() + "^FS\n" + "^FO28,48^A0,15,14^FDCANT: " + cantidadEtiquetas + " PRECIO " + precio + "^FS\n" + "^FO05,95^A0,18,10^FD" + departmentCode + "-" + lineCode + "-" + seccionCode + "- " + product_plus_correlative + "^FS\n" + "^FO05,120^A0,18,10^FD" + name + "^FS\n" + "^FO05,140^A0,18,10^FD ^FS\n" + "^PQ1^FS\n" + "^XZ"; } else { s = "^XA^PRD^XZ\n" + "^XA^JMA^\n" + "^LH07,02^FS\n" + "^FO10,03^BE,25,N^BY3, 0.5,45^FD" + product_plus_correlative + "^FS\n" + "^FO10,62^AA,15,12^FD" + departmentCode + "-" + lineCode + "-" + seccionCode + "-" + product_plus_correlative + " ^FS\n" + "^FO10,82^AA,20,10^FD" + name + "^FS\n" + "^FO10,97^AA,20,10^FD ^FS\n" + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n" + "^FO10,170^AB,11,07^FDRIF J-00046517-7 Exento de Iva%^FS\n" + "^FO10,153^AB,11,07^CI10^FD" + semana + " " + mes + " " + año + "^FS\n" + "^FO10,138^AA,11,09^FDBsF.^FS\n" + "^FO35,136^AB,11,07^CI10^FD " + precio + "^FS\n" + "^PQ" + cantidadEtiquetas + "^FS\n" + "^XZ\n" + // Control label "^XA^PRD^XZ\n" + "^XA^JMA^\n" + "^LH00,15^FS\n" + "^FO2,5^AD,38,10^FD*CONTROL* " + semana + " " + mes + "" + año + "^FS\n" + "^FO05,45^A0,30,07^FD TDA: " + tienda.getValue() + "^FS\n" + "^FO28,48^A0,15,14^FDCANT: " + cantidadEtiquetas + " PRECIO " + precio + "^FS\n" + "^FO05,95^A0,18,10^FD" + departmentCode + "-" + lineCode + "-" + seccionCode + "- " + product_plus_correlative + "^FS\n" + "^FO05,120^A0,18,10^FD" + name + "^FS\n" + "^FO05,140^A0,18,10^FD ^FS\n" + "^PQ1^FS\n" + "^XZ"; } byte[] by = s.getBytes(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(by, flavor, null); job.print(doc, null); } catch (Exception e) { e.printStackTrace(); } }
/** Process Button Pressed - Process Matching */ private void cmd_newProduct() { // Selecciono el departamento int depart = 0; String SQL = "Select XX_VMR_DEPARTMENT_ID " + "from XX_VMR_VENDORPRODREF " + "where XX_VMR_VENDORPRODREF_ID=" + LineRefProv.getXX_VMR_VendorProdRef_ID(); try { PreparedStatement pstmt = DB.prepareStatement(SQL, null); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { depart = rs.getInt("XX_VMR_DEPARTMENT_ID"); } rs.close(); pstmt.close(); } catch (Exception a) { log.log(Level.SEVERE, SQL, a); } MVMRVendorProdRef vendorProdRef = new MVMRVendorProdRef(Env.getCtx(), LineRefProv.getXX_VMR_VendorProdRef_ID(), null); if (vendorProdRef.getXX_VMR_ProductClass_ID() > 0 && vendorProdRef.getXX_VMR_TypeLabel_ID() > 0) { MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null); // Selecciono el departamento X_XX_VMR_Department dept = new X_XX_VMR_Department(Env.getCtx(), vendorProdRef.getXX_VMR_Department_ID(), null); int category = dept.getXX_VMR_Category_ID(); // Selecciono la línea X_XX_VMR_Line line = new X_XX_VMR_Line(Env.getCtx(), vendorProdRef.getXX_VMR_Line_ID(), null); int typeInventory = line.getXX_VMR_TypeInventory_ID(); MProduct newProduct = new MProduct( Env.getCtx(), vendorProdRef.getXX_VMR_Department_ID(), vendorProdRef.getXX_VMR_Line_ID(), vendorProdRef.getXX_VMR_Section_ID(), vendorProdRef.get_ID(), vendorProdRef.getC_TaxCategory_ID(), vendorProdRef.getXX_VME_ConceptValue_ID(), typeInventory, null); // Se buscará si por la referencia para producto ya existe para asignarle el Tipo de // Exhibición String sql = "select * from M_Product where XX_VMR_DEPARTMENT_ID = " + vendorProdRef.getXX_VMR_Department_ID() + " and " + "XX_VMR_LINE_ID = " + vendorProdRef.getXX_VMR_Line_ID() + " and XX_VMR_SECTION_ID = " + vendorProdRef.getXX_VMR_Section_ID() + " and " + "XX_VMR_VendorProdRef_id = " + vendorProdRef.getXX_VMR_VendorProdRef_ID() + " order by M_Product_ID desc"; PreparedStatement pstmt = DB.prepareStatement(sql, null); ResultSet rs = null; try { rs = pstmt.executeQuery(); if (rs.next()) newProduct.setXX_VMR_TypeExhibition_ID(rs.getInt("XX_VMR_TypeExhibition_ID")); } catch (SQLException e) { e.printStackTrace(); } finally { DB.closeResultSet(rs); DB.closeStatement(pstmt); } if (vendorProdRef.getXX_VMR_Section_ID() > 0) { X_XX_VMR_Section section = new X_XX_VMR_Section(Env.getCtx(), vendorProdRef.getXX_VMR_Section_ID(), null); newProduct.setName(section.getName()); } else { newProduct.setName(vendorProdRef.getName()); } newProduct.setXX_VMR_Category_ID(category); newProduct.setXX_VMR_LongCharacteristic_ID(vendorProdRef.getXX_VMR_LongCharacteristic_ID()); newProduct.setXX_VMR_Brand_ID(vendorProdRef.getXX_VMR_Brand_ID()); newProduct.setXX_VMR_UnitConversion_ID(vendorProdRef.getXX_VMR_UnitConversion_ID()); newProduct.setXX_PiecesBySale_ID(vendorProdRef.getXX_PiecesBySale_ID()); newProduct.setXX_VMR_UnitPurchase_ID(vendorProdRef.getXX_VMR_UnitPurchase_ID()); newProduct.setXX_SaleUnit_ID(vendorProdRef.getXX_SaleUnit_ID()); newProduct.setC_Country_ID(order.getC_Country_ID()); newProduct.setIsActive(true); newProduct.setC_BPartner_ID(vendorProdRef.getC_BPartner_ID()); newProduct.setXX_VMR_TypeLabel_ID(vendorProdRef.getXX_VMR_TypeLabel_ID()); newProduct.setXX_VMR_ProductClass_ID(vendorProdRef.getXX_VMR_ProductClass_ID()); newProduct.setM_AttributeSet_ID(Env.getCtx().getContextAsInt("#XX_L_P_ATTRIBUTESETST_ID")); newProduct.setProductType(X_Ref_M_Product_ProductType.ITEM.getValue()); newProduct.save(); } else { // Creo variables de sesion para atraparlas en la ventana producto Env.getCtx().setContext("#Depart_Aux", depart); Env.getCtx().setContext("#Section_Aux", LineRefProv.getXX_VMR_Section_ID()); Env.getCtx().setContext("#Line_Aux", LineRefProv.getXX_VMR_Line_ID()); Env.getCtx().setContext("#VendorRef_Aux", LineRefProv.getXX_VMR_VendorProdRef_ID()); Env.getCtx().setContext("#FromProcess_Aux", "Y"); AWindow window_product = new AWindow(); Query query = Query.getNoRecordQuery("M_Product", true); window_product.initWindow(140, query); AEnv.showCenterScreen(window_product); // Obtenemos el GridController para setear la variable m_changed=true JRootPane jRootPane = ((JRootPane) window_product.getComponent(0)); JLayeredPane jLayeredPane = (JLayeredPane) jRootPane.getComponent(1); JPanel jPanel = (JPanel) jLayeredPane.getComponent(0); APanel aPanel = (APanel) jPanel.getComponent(0); VTabbedPane vTabbedPane = (VTabbedPane) aPanel.getComponent(0); GridController gridController = (GridController) vTabbedPane.getComponent(0); GridTable mTable = gridController.getMTab().getTableModel(); mTable.setChanged(true); MProduct.loadLineRefProv(LineRefProv, Env.getCtx()); // Borro las variables de sesion creadas Env.getCtx().remove("#Depart_Aux"); Env.getCtx().remove("#FromProcess_Aux"); Env.getCtx().remove("#Line_Aux"); Env.getCtx().remove("#Section_Aux"); Env.getCtx().remove("#VendorRef_Aux"); } } // cmd_newProduct