Ejemplo n.º 1
0
  private PlainDeliveryDayQueryParams createDeliveryDayQueryParams(
      final IDeliveryDayAllocable deliveryDayAllocable) {
    final PlainDeliveryDayQueryParams params = new PlainDeliveryDayQueryParams();
    params.setC_BPartner_Location_ID(deliveryDayAllocable.getC_BPartner_Location_ID());
    params.setDeliveryDate(deliveryDayAllocable.getDeliveryDate());
    params.setToBeFetched(deliveryDayAllocable.isToBeFetched());

    return params;
  }
Ejemplo n.º 2
0
  @Override
  public Timestamp calculatePreparationDateOrNull(
      IContextAware context,
      boolean isSOTrx,
      Timestamp datePromised,
      final int bpartnerLocationId) {
    // task 09004: add the current time as parameter and fetch the closest next fit delivery day
    final Timestamp calculationTime = SystemTime.asTimestamp();

    //
    // Create Delivery Day Query Parameters
    final PlainDeliveryDayQueryParams deliveryDayQueryParams = new PlainDeliveryDayQueryParams();
    deliveryDayQueryParams.setC_BPartner_Location_ID(bpartnerLocationId);
    deliveryDayQueryParams.setDeliveryDate(datePromised);
    deliveryDayQueryParams.setToBeFetched(!isSOTrx);
    deliveryDayQueryParams.setProcessed(false);
    deliveryDayQueryParams.setCalculationTime(calculationTime);

    //
    // Find matching delivery day record
    final IDeliveryDayDAO deliveryDayDAO = Services.get(IDeliveryDayDAO.class);
    final I_M_DeliveryDay dd = deliveryDayDAO.retrieveDeliveryDay(context, deliveryDayQueryParams);

    //
    // Extract PreparationDate from DeliveryDay record
    final Timestamp preparationDate;
    if (dd == null) {
      preparationDate = null;
    } else {
      preparationDate = dd.getDeliveryDate();
    }

    return preparationDate;
  }
Ejemplo n.º 3
0
  @Override
  public I_M_DeliveryDay_Alloc getCreateDeliveryDayAlloc(
      final IContextAware context, final IDeliveryDayAllocable model) {
    final IDeliveryDayDAO deliveryDayDAO = Services.get(IDeliveryDayDAO.class);

    final PlainDeliveryDayQueryParams deliveryDayMatchingParams =
        createDeliveryDayQueryParams(model);

    //
    //
    I_M_DeliveryDay_Alloc deliveryDayAlloc =
        deliveryDayDAO.retrieveDeliveryDayAllocForModel(context, model);
    if (deliveryDayAlloc != null) {
      final I_M_DeliveryDay deliveryDayCurrent = deliveryDayAlloc.getM_DeliveryDay();

      if (!deliveryDayDAO.isDeliveryDayMatches(deliveryDayCurrent, deliveryDayMatchingParams)) {
        // Delivery Date is not matching anymore => we need to destroy this allocation
        InterfaceWrapperHelper.delete(deliveryDayAlloc);
        deliveryDayAlloc = null;
      }
    }

    //
    // Create a new Delivery Day Allocation if we don't have one yet
    // ... and get the the Delivery Day record
    if (deliveryDayAlloc == null) {
      deliveryDayMatchingParams.setProcessed(false); // only not processed delivery days
      final I_M_DeliveryDay deliveryDay =
          deliveryDayDAO.retrieveDeliveryDay(context, deliveryDayMatchingParams);
      if (deliveryDay != null) {
        deliveryDayAlloc = createDeliveryDayAlloc(context, deliveryDay, model);
      }
    }

    return deliveryDayAlloc;
  }