Esempio n. 1
0
 private int calcWorkingDayNum() {
   DateTime start = sprint.getStartDate();
   DateTime end = sprint.getEndDate();
   start = start.minusMillis(start.millisOfDay().get());
   end = end.minusMillis(end.millisOfDay().get());
   int i = 0;
   for (; start.isBefore(end); start = start.plusDays(1)) {
     if (start.getDayOfWeek() < DateTimeConstants.SATURDAY) {
       i++;
     }
   }
   return i;
 }
  private boolean isAnyNewestItem(
      Date date, String idGoods, StockType stockType, Date consumptionTimeStamp) {

    DateTime date2 = new DateTime();
    // Variabel untuk tanggal mulai hari. untuk menghitung juga data pada hari yang sama
    DateTime dateTimeStartDay = new DateTime(date).withMillisOfDay(0);
    // variabel untuk tanggal akhir hari. Agar tidak menghitung tanggal pada hari yang sama.
    DateTime dateTimeEndDay =
        new DateTime(date).withMillisOfDay(date2.millisOfDay().getMaximumValue());

    Goods goods = server.find(Goods.class, idGoods);

    boolean receptionResult;
    boolean deletionResult;
    boolean consumptionResult;
    switch (stockType) {
      case CONSUMPTION:
        receptionResult = isAnyReception(dateTimeStartDay, goods);
        deletionResult = isAnyDeletion(dateTimeStartDay, goods);
        consumptionResult = isAnyConsumption(dateTimeEndDay, goods);
        // jika tidak ditemukan konsumsi, maka pastikan tidak ada konsumsi lain pada hari yang sama
        // yang di input setelah konsumsi ini.
        if (!consumptionResult) {
          consumptionResult =
              isConsumptionNotLastOfTheDay(dateTimeStartDay, goods, consumptionTimeStamp);
        }
        break;
      case RECEPTION:
        receptionResult = isAnyReception(dateTimeEndDay, goods); // beda variabel
        deletionResult = isAnyDeletion(dateTimeStartDay, goods);
        consumptionResult = isAnyConsumption(dateTimeStartDay, goods);
        break;
      case DELETION:
        receptionResult = isAnyReception(dateTimeStartDay, goods);
        deletionResult = isAnyDeletion(dateTimeStartDay, goods);
        consumptionResult = isAnyConsumption(dateTimeStartDay, goods);
        break;
      default:
        receptionResult = false;
        deletionResult = false;
        consumptionResult = false;
        break;
    }

    // jika ada recepsi, deletion, dan konsumsi : maka true
    return receptionResult || deletionResult || consumptionResult ? true : false;
  }
  // Untuk menentukan suatu konsumsi merupakan yang terakhir di input
  private boolean isConsumptionNotLastOfTheDay(DateTime day, Goods goods, Date timestamp) {
    Date startDate = day.withMillisOfDay(0).toDate();
    Date endDate = day.withMillisOfDay(day.millisOfDay().getMaximumValue()).toDate();

    List<GoodsConsumption> goodList =
        server
            .find(GoodsConsumption.class)
            .where()
            .between("consumptionDate", startDate, endDate)
            .eq("goods", goods)
            .findList();
    for (GoodsConsumption consumption : goodList) {
      DateTime consumptionTimeStamp = new DateTime(consumption.getTimestamp());
      DateTime currentTimeStamp = new DateTime(timestamp);
      if (consumptionTimeStamp.isAfter(currentTimeStamp)) {
        return true;
      }
    }

    return false;
  }
  public boolean isDateValid(Date date, String idGoods) {
    if (idGoods == null) {
      System.out.println("goods null");
      return true;
    }

    DateTime date2 = new DateTime();

    // variabel untuk tanggal akhir hari. Agar tidak menghitung tanggal pada hari yang sama.
    DateTime dateTimeEndDay =
        new DateTime(date).withMillisOfDay(date2.millisOfDay().getMaximumValue());
    Goods goods = server.find(Goods.class, idGoods);

    boolean anyConsumption = isAnyConsumption(dateTimeEndDay, goods);
    boolean anyDeletion = isAnyDeletion(dateTimeEndDay, goods);
    boolean anyReception = isAnyReception(dateTimeEndDay, goods);
    System.out.println("GOods " + idGoods);
    System.out.println("anyConsumption " + anyConsumption);
    System.out.println("anyDeletion " + anyDeletion);
    System.out.println("anyReception " + anyReception);
    return anyConsumption || anyDeletion || anyReception ? false : true;
  }