Пример #1
0
  private void btnToUnbekanntActionPerformed(ActionEvent e) {
    Lager unbekannt = LagerTools.getUnbekannt();
    StockTableModel2 model = (StockTableModel2) tblVorrat.getModel();
    Tools.log(txtLog, "Folgende Vorräte wurden auf Unbekannt umgebucht:");
    Tools.log(txtLog, "================================================");

    EntityManager em = Main.getEMF().createEntityManager();
    try {
      em.getTransaction().begin();

      for (int row = 0; row < model.getRowCount(); row++) {
        // Model Row Index Umwandlung ist hier unnötig. Markierungen bleiben unberücksichtigt.
        if (model.getStatus(row) == StockTableModel2.STATUS_FRAGLICH) {
          Stock stock = em.merge(model.getVorrat(row));
          em.lock(stock, LockModeType.OPTIMISTIC);
          Tools.log(txtLog, stock.getId(), stock.getProdukt().getBezeichnung(), "");
          stock.setLager(unbekannt);
        }
      }
      em.getTransaction().commit();
    } catch (OptimisticLockException ole) {
      em.getTransaction().rollback();
      Main.warn(ole);
    } catch (Exception ex) {
      em.getTransaction().rollback();
      Main.fatal(ex);
    } finally {
      em.close();
      loadVorratTable();
    }
    Tools.log(txtLog, "================================================");
  }
Пример #2
0
 private void jButton2ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed
   // TODO add your handling code here:
   Stock s = new Stock();
   s.setVisible(true);
   setVisible(false);
   dispose();
 } // GEN-LAST:event_jButton2ActionPerformed
Пример #3
0
  public static String getIngTypesAndStocksAsHTML2(Menuweekall menuweekall) {
    //        SimpleDateFormat sdf = new SimpleDateFormat("EEEE, d. MMMM yyyy");

    String html = "";

    LocalDate startDay = new LocalDate(menuweekall.getWeek());

    for (int day = 0; day < 7; day++) {
      LocalDate thisDay = startDay.plusDays(day);

      String dayHTML = ""; // HTML.h1(thisDay.toString("EEEE, d. MMMM yyyy"));

      boolean firstMenuThisDay = true; // just for the pagebreak
      for (Menuweek menuweek : menuweekall.getMenuweeks()) {
        Menuweek2Menu menuweek2Menu = menuweek.getMenuweek2menus().get(day);
        Menu menu = menuweek2Menu.getMenu();

        if (!menu.isEmpty()) {
          if (!firstMenuThisDay) dayHTML += HTML.pagebreak();
          firstMenuThisDay = false;
          dayHTML +=
              HTML.h1(
                  menuweek.getRecipefeature().getText()
                      + " ("
                      + thisDay.toString("EEEE, d. MMMM yyyy")
                      + ")");

          for (int dish : MenuTools.DISHES) {
            Recipes recipe = MenuTools.getDish(menu, dish);

            if (recipe != null) {

              dayHTML += HTML.h2(recipe.getTitle());
              String list = RecipeTools.getSubRecipesAsHTML(MenuTools.getDish(menu, dish));

              Set<Stock> stocks = MenuTools.getStocklist(menu, dish);
              for (Stock stock : stocks) {
                list += HTML.li(stock.getId() + ": " + stock.getProdukt().getBezeichnung());
              }
              dayHTML += HTML.ul(list);
            }
          }
        }
      }
      html += dayHTML;
      if (day < 6) html += HTML.pagebreak();
    }

    return html;
  }
Пример #4
0
 private void txtSearchActionPerformed(ActionEvent e) {
   stock = StockTools.findByIDORScanner(txtSearch.getText());
   if (stock != null) {
     if (stock.isAusgebucht() && !cbZombieRevive.isSelected()) {
       Tools.log(
           txtLog,
           stock.getId(),
           stock.getProdukt().getBezeichnung(),
           "Dieser Vorrat wurde bereits ausgebucht.");
       Tools.fadeout(lblProdukt);
       sp.error();
       stock = null;
     } else {
       if (btnSofortUmbuchen.isSelected()) {
         umbuchen();
         Tools.fadeinout(
             lblProdukt, "[" + stock.getId() + "] " + stock.getProdukt().getBezeichnung());
         stock = null;
       } else {
         Tools.fadein(
             lblProdukt, "[" + stock.getId() + "] " + stock.getProdukt().getBezeichnung());
       }
     }
   } else {
     Tools.log(txtLog, 0, txtSearch.getText(), "Unbekannte Vorrat Nummer.");
     Tools.fadeout(lblProdukt);
     sp.warning();
   }
   btnUmbuchen.setEnabled(stock != null);
   txtSearch.selectAll();
   txtSearch.requestFocus();
   txtSearchChecked = true;
 }
Пример #5
0
 private void vorratsListeInsLogbuch() {
   if (tblVorrat.getModel().getRowCount() > 0) {
     StockTableModel2 model = (StockTableModel2) tblVorrat.getModel();
     Tools.log(txtLog, "Die Vorratsliste enhielt folgende Einträge:");
     Tools.log(txtLog, "===========================================");
     for (int row = 0; row < model.getRowCount(); row++) {
       int r = tblVorrat.convertRowIndexToModel(row);
       Stock stock = model.getVorrat(r);
       String status = "";
       if (model.getStatus(r) == StockTableModel2.STATUS_FRAGLICH) {
         status = "ungeprüft";
       } else if (model.getStatus(r) == StockTableModel2.STATUS_NEU) {
         status = "   neu   ";
       } else if (model.getStatus(r) == StockTableModel2.STATUS_OK) {
         status = "    ok   ";
       } else {
         status = "?";
       }
       Tools.log(txtLog, stock.getId(), status, stock.getProdukt().getBezeichnung());
     }
     Tools.log(txtLog, "================================================");
   }
 }
Пример #6
0
  private void btnAusbuchenActionPerformed(ActionEvent e) {
    EntityManager em = Main.getEMF().createEntityManager();
    try {
      em.getTransaction().begin();
      int[] rows = tblVorrat.getSelectedRows();

      for (int r = 0; r < rows.length; r++) {
        // Diese Zeile ist sehr wichtig, da sie die Auswahl in der Tabelle bzgl. einer Umsortierung
        // berücksichtigt.
        int row = tblVorrat.convertRowIndexToModel(rows[r]);
        Stock stock = ((StockTableModel2) tblVorrat.getModel()).getVorrat(row);

        Main.logger.info("AUSBUCHEN STOCK: " + stock.toString());
        Tools.log(txtLog, stock.getId(), stock.getProdukt().getBezeichnung(), "AUSGEBUCHT");
        StockTools.ausbuchen(stock, "Abschlussbuchung");
      }
      em.getTransaction().commit();
    } catch (Exception e1) {
      em.getTransaction().rollback();
    } finally {
      em.close();
      loadVorratTable();
    }
  }
Пример #7
0
  public static String getIngTypesAndStocksAsHTML(Menuweekall menuweekall) {
    //        SimpleDateFormat sdf = new SimpleDateFormat("EEEE, d. MMMM yyyy");

    String html = "<h1 id=\"fonth1\">Zutaten und Vorräte</h1>";

    HashSet<Additives> setAdditives = new HashSet<Additives>();
    HashSet<Allergene> setAllergenes = new HashSet<Allergene>();

    LocalDate startDay = new LocalDate(menuweekall.getWeek());

    String outerTable = "";

    for (int day = 0; day < 6; day++) {
      LocalDate thisDay = startDay.plusDays(day);
      outerTable +=
          HTML.table_tr(
              HTML.table_th(HTML.fontface + thisDay.toString("EEEE, d. MMMM yyyy") + "</font>", 2));

      String midTable = "";
      for (Menuweek menuweek : menuweekall.getMenuweeks()) {
        Menuweek2Menu menuweek2Menu = menuweek.getMenuweek2menus().get(day);
        Menu menu = menuweek2Menu.getMenu();

        if (!menu.isEmpty()) {
          outerTable +=
              HTML.table_tr(
                  HTML.table_th(
                      menuweek2Menu.getMenu().getText()
                          + " ("
                          + menuweek.getRecipefeature().getText()
                          + ")",
                      2));

          for (int dish : MenuTools.DISHES) {
            Recipes recipe = MenuTools.getDish(menu, dish);

            if (recipe != null) {

              outerTable += HTML.table_tr(HTML.table_td(recipe.getTitle(), 2));

              outerTable += HTML.table_tr(HTML.table_td("Zutaten") + HTML.table_td("Vorräte"));

              String ingList =
                  recipe.getIngTypes2Recipes().isEmpty() ? HTML.li(HTML.italic("leer...")) : "";
              for (Ingtypes2Recipes it2r : recipe.getIngTypes2Recipes()) {
                ingList +=
                    HTML.li(
                        it2r.getIngType().getBezeichnung()
                            + (it2r.getAmount().compareTo(BigDecimal.ZERO) > 0
                                ? ", "
                                    + it2r.getAmount()
                                    + " "
                                    + IngTypesTools.EINHEIT[it2r.getIngType().getEinheit()]
                                : ""));
              }

              Set<Stock> stocks = MenuTools.getStocklist(menu, dish);
              String stocklist = stocks.isEmpty() ? HTML.li(HTML.italic("leer...")) : "";
              for (Stock stock : stocks) {
                stocklist += HTML.li(stock.getId() + ": " + stock.getProdukt().getBezeichnung());
              }

              outerTable +=
                  HTML.table_tr(
                      HTML.table_td(HTML.ul(ingList)) + HTML.table_td(HTML.ul(stocklist)));
            }
          }
        }

        //                outerTable += HTML.table_tr(
        //                        HTML.table(
        //                                midTable
        //                                ,"1"
        //                        )
        //                );

      }
    }

    html += HTML.table(outerTable, "1");

    //        // print a keymap on the next page
    //        if (!setAdditives.isEmpty() || !setAllergenes.isEmpty()) {
    //            html += "<h1 id=\"fonth1\" style=\"page-break-before:always\">Legende</h1>";
    //
    //            if (!setAllergenes.isEmpty()) {
    //                html += "<h2 id=\"fonth2\">Allergene</h2>";
    //                html += "<ul>";
    //
    //                ArrayList<Allergene> list = new ArrayList<Allergene>(setAllergenes);
    //                Collections.sort(list);
    //
    //                for (Allergene allergene : list) {
    //                    html += "<li><b>" + allergene.getKennung() + "</b> " +
    // allergene.getText();
    //                }
    //
    //                html += "</ul>";
    //            }
    //
    //            if (!setAdditives.isEmpty()) {
    //                html += "<h2 id=\"fonth2\">Zusatzstoffe</h2>";
    //                html += "<ul>";
    //
    //                ArrayList<Additives> list = new ArrayList<Additives>(setAdditives);
    //                Collections.sort(list);
    //
    //                for (Additives additive : list) {
    //                    html += "<li><b>" + additive.getSymbol() + "</b> " + additive.getName() +
    // (additive.getText().isEmpty() ? "" : " <i>" + additive.getText() + "</i>");
    //                }
    //
    //                html += "</ul>";
    //            }
    //        }

    return html;
  }
Пример #8
0
  private void umbuchen() {

    EntityManager em = Main.getEMF().createEntityManager();
    try {

      em.getTransaction().begin();

      Stock myStock = em.merge(stock);

      if (myStock.isAusgebucht()) {
        myStock.setAusgang(Const.DATE_BIS_AUF_WEITERES);
        myStock.setAnbruch(Const.DATE_BIS_AUF_WEITERES);

        Query query =
            em.createQuery(
                "DELETE FROM Buchungen b WHERE b.stock = :vorrat AND b.status <> :butnotstatus");
        query.setParameter("vorrat", myStock);
        query.setParameter("butnotstatus", BuchungenTools.BUCHEN_EINBUCHEN_ANFANGSBESTAND);

        query.executeUpdate();

        //                Collection<Buchungen> buchungen = myVorrat.getBuchungenCollection();
        //                for (Buchungen b : buchungen) {
        //                    Buchungen buchung = em.merge(b);
        //                    if (buchung.getStatus() !=
        // BuchungenTools.BUCHEN_EINBUCHEN_ANFANGSBESTAND) {
        //                        em.remove(buchung);
        //                    }
        //                }
        //                for (Buchungen b : buchungen) {
        //                    if (b.getStatus() != BuchungenTools.BUCHEN_EINBUCHEN_ANFANGSBESTAND) {
        //                        myVorrat.getBuchungenCollection().remove(b);
        //                    }
        //                }
      }

      myStock.setLager(em.merge(ziel));
      if (lieferant != null) {
        myStock.setLieferant(em.merge(lieferant));
      }
      //            EntityTools.merge(vorrat);
      em.getTransaction().commit();

      stock = myStock;

      Tools.log(txtLog, myStock.getId(), myStock.getProdukt().getBezeichnung(), "umgebucht");
      if (tblVorrat.getModel() instanceof StockTableModel2) {
        int row =
            ((StockTableModel2) tblVorrat.getModel())
                .addVorrat(stock); // diese Methode fügt den Vorrat nur dann hinzu, wenn nötig.
        Tools.scrollCellToVisible(tblVorrat, row, 1);
        tblVorrat.getSelectionModel().setSelectionInterval(row, row);
      }
      sp.bell();

    } catch (Exception ee) {
      em.getTransaction().rollback();
      ee.printStackTrace();
    } finally {
      em.close();
    }
  }