/** 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;
    }
  }