Dashboards widgets
This commit is contained in:
@@ -88,6 +88,123 @@ class Wiaas_Delivery_Process {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivery dates cannot be set if:
|
||||
* - user cannot edit delivery dates
|
||||
* - actions for customer config validation is not done
|
||||
* - action for customer acceptance is active or completed
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param mixed $delivery_process_entry
|
||||
* @param array $steps
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function can_delivery_dates_be_set($order_id, $delivery_process_entry = null, $steps = null) {
|
||||
|
||||
if ( empty($delivery_process_entry) ) {
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
}
|
||||
|
||||
if (empty($delivery_process_entry) || ! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' )) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
$current_step = $workflow_api->get_current_step($delivery_process_entry);
|
||||
|
||||
if ( empty($steps) ) {
|
||||
$steps = $workflow_api->get_steps();
|
||||
}
|
||||
|
||||
foreach ($steps as $step) {
|
||||
$step = $workflow_api->get_step($step->get_id(), $delivery_process_entry);
|
||||
|
||||
// customer validation not done
|
||||
if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_validate_questionnaires_action($step) &&
|
||||
$step->get_status() !== 'complete') {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// customer acceptance is active or completed
|
||||
if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_acceptance_action($step) &&
|
||||
($current_step && $step->get_id() === $current_step->get_id() || $step->get_status() === 'complete')) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_next_actions_for_current_user() {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$field_filters = array();
|
||||
$field_filters[] = array(
|
||||
'key' => 'workflow_user_id_' . $current_user->ID,
|
||||
'value' => 'pending',
|
||||
);
|
||||
|
||||
$user_roles = gravity_flow()->get_user_roles();
|
||||
foreach ( $user_roles as $user_role ) {
|
||||
$field_filters[] = array(
|
||||
'key' => 'workflow_role_' . $user_role,
|
||||
'value' => 'pending',
|
||||
);
|
||||
}
|
||||
|
||||
$field_filters['mode'] = 'any';
|
||||
|
||||
$search_criteria = array();
|
||||
$search_criteria['field_filters'] = $field_filters;
|
||||
$search_criteria['status'] = 'active';
|
||||
|
||||
$form_ids = gravity_flow()->get_workflow_form_ids();
|
||||
|
||||
$entries = GFAPI::get_entries(
|
||||
$form_ids,
|
||||
$search_criteria,
|
||||
null,
|
||||
null);
|
||||
|
||||
$actions = array();
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
if (! $order) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$step = gravity_flow()->get_step( $entry['workflow_step'] );
|
||||
|
||||
if (!$step) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$action = array(
|
||||
'order_id' => $order_id,
|
||||
'order_number' => $order->get_order_number(),
|
||||
'action_title' => $step->get_name()
|
||||
);
|
||||
|
||||
if (is_admin()) {
|
||||
$action['url'] = '?page=gravityflow-inbox&view=entry&id=' . $entry['form_id'] . '&lid=' . $entry['id'];
|
||||
}
|
||||
|
||||
$actions[] = $action;
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe complete parent order for completed delivery process
|
||||
* @param $entry_id
|
||||
|
||||
Reference in New Issue
Block a user