Search in sources :

Example 6 with OrderState

use of com.qcadoo.mes.orders.states.constants.OrderState in project mes by qcadoo.

the class OrderHooks method auditDatesChanges.

private void auditDatesChanges(final Entity order) {
    boolean datesChanged = order.getBooleanField(OrderFields.DATES_CHANGED);
    OrderState orderState = OrderState.of(order);
    if (datesChanged && !orderState.equals(OrderState.PENDING)) {
        order.setField(OrderFields.DATES_CHANGED, false);
        DataDefinition orderStateChangeDD = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER_STATE_CHANGE);
        Entity orderStateChange = orderStateChangeDD.create();
        orderStateChange.setField(OrderStateChangeFields.DATES_CHANGED, true);
        orderStateChange.setField(OrderStateChangeFields.ORDER, order);
        orderStateChange.setField(OrderStateChangeFields.SOURCE_CORRECTED_DATE_FROM, order.getField(OrderFields.SOURCE_CORRECTED_DATE_FROM));
        orderStateChange.setField(OrderStateChangeFields.SOURCE_CORRECTED_DATE_TO, order.getField(OrderFields.SOURCE_CORRECTED_DATE_TO));
        orderStateChange.setField(OrderStateChangeFields.SOURCE_FINISH_DATE, order.getField(OrderFields.SOURCE_FINISH_DATE));
        orderStateChange.setField(OrderStateChangeFields.SOURCE_START_DATE, order.getField(OrderFields.SOURCE_START_DATE));
        orderStateChange.setField(OrderStateChangeFields.TARGET_CORRECTED_DATE_FROM, order.getField(OrderFields.CORRECTED_DATE_FROM));
        orderStateChange.setField(OrderStateChangeFields.TARGET_CORRECTED_DATE_TO, order.getField(OrderFields.CORRECTED_DATE_TO));
        orderStateChange.setField(OrderStateChangeFields.TARGET_FINISH_DATE, order.getField(OrderFields.FINISH_DATE));
        orderStateChange.setField(OrderStateChangeFields.TARGET_START_DATE, order.getField(OrderFields.START_DATE));
        orderStateChange.setField(OrderStateChangeFields.SOURCE_STATE, order.getField(OrderFields.STATE));
        orderStateChange.setField(OrderStateChangeFields.TARGET_STATE, order.getField(OrderFields.STATE));
        String workerToChange = order.getStringField(OrderFields.WORKER_TO_CHANGE);
        if (StringUtils.isEmpty(workerToChange)) {
            orderStateChange.setField(OrderStateChangeFields.WORKER, userService.getCurrentUserEntity().getField(UserFields.USER_NAME));
        } else {
            orderStateChange.setField(OrderStateChangeFields.WORKER, workerToChange);
            order.setField(OrderFields.WORKER_TO_CHANGE, null);
        }
        orderStateChange.setField("dateAndTime", setDateToField(new Date()));
        orderStateChange.setField(OrderStateChangeFields.STATUS, "03successful");
        orderStateChangeDD.save(orderStateChange);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) OrderState(com.qcadoo.mes.orders.states.constants.OrderState) DataDefinition(com.qcadoo.model.api.DataDefinition) Date(java.util.Date)

Aggregations

OrderState (com.qcadoo.mes.orders.states.constants.OrderState)6 Entity (com.qcadoo.model.api.Entity)5 ProgressType (com.qcadoo.mes.productionPerShift.constants.ProgressType)2 AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)2 Date (java.util.Date)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 FormComponent (com.qcadoo.view.api.components.FormComponent)1