\d+)', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'upload_customer_questionnaire'),
- //'permission_callback' => 'is_user_logged_in'
+ 'permission_callback' => 'is_user_logged_in'
) );
}
@@ -114,132 +116,53 @@ class Wiass_REST_Delivery_Process_API {
$order_id = absint($request['order_id']);
-
- $data = Wiaas_Delivery_Process::get_current_delivery_step_info($order_id);
+ $data = Wiaas_Delivery_Process::get_customer_questionnaires_data($order_id);
return rest_ensure_response($data);
}
public function upload_customer_questionnaire(WP_REST_Request $request) {
- $action_id = absint($request['action_id']);
+ $order_id = absint($request['order_id']);
- try {
+ $action_entry_id = absint($request['action_entry_id']);
- $result = Wiaas_Document_Upload::upload_document_version();
-
- $entry = GFAPI::get_entry($action_id);
-
- $document_field = GFCommon::get_fields_by_type(GFAPI::get_form($entry['form_id']), 'wiaas_order_bundle_document')[0];
-
- $entry[$document_field->id] = $result;
-
- GFAPI::update_entry($entry);
-
- Wiaas_Delivery_Process::complete_action_step($action_id);
-
- return rest_ensure_response($result);
-
- } catch( Exception $e) {
- }
+ Wiaas_Delivery_Process::upload_customer_questionnaire($order_id, $action_entry_id);
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
public static function get_customer_acceptance(WP_REST_Request $request){
- $entry = GFAPI::get_entry($request['entry_id']);
- if (is_wp_error($entry)){
- return wiaas_api_generate_error('Customer acceptance entry not found', 404);
- }
- $acceptance_documents = array();
- $uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
+ $order_id = absint($request['order_id']);
- foreach($uploaded_files as $file_url){
- //example of decoded url :
- //http://localhost/wp/index.php?gf-download=2018/08/rokovi-1535378841.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534
-
- $decoded_url = urldecode($file_url);
- $url_parts = explode('?', $decoded_url);
- $file_name_base_parts = explode('&', $url_parts[1]);
- $file_name_parts = explode('/', $file_name_base_parts[0]);
- $file_name_with_extension_parts = explode('.', $file_name_parts[2]);
+ $data = Wiaas_Delivery_Process::get_customer_acceptance_data($order_id);
- $acceptance_documents_entry = array(
- 'name' => $file_name_with_extension_parts[0],
- 'extension' => $file_name_with_extension_parts[1],
- 'url' => $file_url
- );
-
- array_push($acceptance_documents, $acceptance_documents_entry);
- }
-
- $acceptance_status = 0;
- if ($entry[self::ACCEPTANCE_STATUS_FIELD_ID]){
- $acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
- }
-
- return rest_ensure_response(array(
- 'documents' => $acceptance_documents,
- 'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
- 'status' => $acceptance_status,
- 'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
- ));
+ return rest_ensure_response($data);
}
- public static function submit_customer_acceptance(WP_REST_Request $request){
- $entry = GFAPI::get_entry($request['entry_id']);
- if (is_wp_error($entry)){
- return wiaas_api_generate_error('Customer acceptance entry not found', 404);
- }
+ public static function submit_customer_acceptance(WP_REST_Request $request) {
- $status = $request['actionType'];
- $reason = $request['declineReason'];
+ $status = $request['action_type'];
+ $reason = $request['decline_reason'];
if (!in_array($status, self::ACCEPTABLE_STATUS)){
return wiaas_api_notice('ACCEPTANCE_STATUS_MISSING', 'error');
}
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
-
- $uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
-
if ($installation_declined && $reason === ''){
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
}
- if (!$installation_declined && (count($uploaded_files)===0)){
+
+ $order_id = $request['order_id'];
+
+ if (! $installation_declined && ! Wiaas_Delivery_Process::is_customer_acceptance_uploaded($order_id)) {
return wiaas_api_notice('ACCEPTANCE_NOT_UPLOADED', 'error');
}
- $entry[self::DECLINE_REASON_FIELD_ID] = $reason;
- $entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
-
- if (!GFAPI::update_entry( $entry )){
- return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
- }
-
- //Check if step is already completed, to not submit again
- $gf_api = new Gravity_Flow_API($entry['form_id']);
- $current_step = $gf_api->get_current_step($entry);
- if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
- return wiaas_api_notice('ACCEPTANCE_STATUS_UPDATED', 'success');
- }
-
- if ( $current_step ) {
- $current_step->purge_assignees();
- $current_step->update_step_status( 'complete' );
- }
- $entry_id = $entry['id'];
- $new_step_id = $current_step->get_id() + 1;
- $new_step = $gf_api->get_step( $new_step_id, $entry );
- $feedback = sprintf( esc_html__( 'Sent to step: %s', 'gravityflow' ), $new_step->get_name() );
- $gf_api->add_timeline_note( $entry_id, $feedback );
- $gf_api->log_activity( 'workflow', 'sent_to_step', $gf_api->form_id, $entry_id, $step_id );
- gform_update_meta( $entry_id, 'workflow_final_status', 'pending' );
- $new_step->start();
- $gf_api->process_workflow( $entry_id );
-
+ Wiaas_Delivery_Process::update_customer_acceptance_status($order_id, $status, $reason);
if ($installation_declined){
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
@@ -247,75 +170,14 @@ class Wiass_REST_Delivery_Process_API {
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
- public static function upload_file(WP_REST_Request $request){
- $files = $request->get_file_params();
- if (!$files[self::FILE_KEY_NAME]){
- return wiaas_api_notice('NO_FILES_UPLOADED', 'error');
- }
+ public static function upload_customer_acceptance(WP_REST_Request $request){
- $entry = GFAPI::get_entry($request['entry_id']);
- if (is_wp_error($entry)){
- return wiaas_api_generate_error('Customer acceptance entry not found', 404);
- }
+ $order_id = $request['order_id'];
- $form = GFAPI::get_form($entry['form_id']);
- $form_upload_path = GFFormsModel::get_upload_path( $form['id'] );
+ $success = Wiaas_Delivery_Process::upload_customer_acceptance_document($order_id);
- $target_path = $form_upload_path . '/' . date('Y') . '/' . date('m') . '/';
- wp_mkdir_p( $target_path );
- GFCommon::recursive_add_index_file( $target_path );
- $upload_file_field = GFAPI::get_field($form['id'], self::UPLOADED_FILES_FIELD_ID);
- $file_name = sanitize_file_name($files[self::FILE_KEY_NAME]['name']);
- $file_path_details = pathinfo($file_name);
-
- if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
- return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
- }
- $allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
- if ( ! empty( $allowed_extensions ) ) {
- if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
- return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
- }
- }
-
- $new_file_name = $file_path_details['filename'] . '-' . time() . '.' . $file_path_details['extension'];
-
- // Bypasses security checks when running unit tests.
- if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
- return wiaas_api_notice('FILE_UPLOADED', 'success');
- }
-
- if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
- GFFormsModel::set_permissions( $target_path . $new_file_name );
- } else {
- return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
- }
-
- //Extract path relative to the root
- //Last 6 strings (excluding last empty) are path relative to the root
- $path_parts = explode('/', $target_path);
-
- $relative_path = '';
- $i = count($path_parts) - self::PATH_PARTS_TO_EXTRACT;
- while($i < count($path_parts)-1){
- $relative_path = $relative_path . $path_parts[$i] . '/';
- $i++;
- }
-
- $file_url = self::BASE_NAME . $relative_path . $new_file_name;
- $url_for_download = $upload_file_field->get_download_url($file_url);
-
- $uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
-
- if ($uploaded_files === NULL){
- $uploaded_files = [];
- }
- array_push($uploaded_files, $url_for_download);
-
- $entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
-
- if (GFAPI::update_entry( $entry )) {
+ if ($success) {
return wiaas_api_notice('FILE_UPLOADED','success');
}
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
index 39d0b48..1e61eef 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
@@ -25,6 +25,9 @@ class Wiaas_Admin {
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.php';
+
+ require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
+
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php
index e7413c9..f5d6dce 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php
@@ -10,8 +10,6 @@ defined( 'ABSPATH' ) || exit;
class Wiaas_Delivery_Process {
- private static $process_form_title_prefix = 'DELIVERY PROCESS:';
-
public static function init() {
self::_register_delivery_process_step_type();
@@ -21,7 +19,7 @@ class Wiaas_Delivery_Process {
private static function _init_hooks() {
add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' ));
- add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 );
+ // add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 );
}
/**
@@ -31,6 +29,7 @@ class Wiaas_Delivery_Process {
require_once( 'delivery-process/class-wiaas-delivery-process-step.php' );
require_once( 'delivery-process/class-wiaas-delivery-process-addon.php' );
+ require_once( 'delivery-process/class-wiaas-delivery-process-action.php' );
// order fields
require_once( 'delivery-process/class-wiaas-order-fields.php' );
@@ -71,6 +70,174 @@ class Wiaas_Delivery_Process {
}
}
+ public static function get_available_process_list_for_country($country_code) {
+
+ $forms = GFAPI::get_forms();
+
+ $available_process_forms = array();
+
+ foreach ($forms as $form) {
+
+ $delivery_settings = rgar($form, 'wiaas_delivery_process');
+
+ if ($delivery_settings['delivery_form_type'] === 'process' &&
+ $delivery_settings['delivery_country'] === $country_code) {
+
+ $available_process_forms[] = $form;
+ }
+ }
+
+ return $available_process_forms;
+ }
+
+
+ public static function get_customer_acceptance_data($order_id) {
+
+ $delivery_process_entry = self::get_order_delivery_process_entry($order_id);
+
+ $data = array();
+
+ if (! empty($delivery_process_entry)) {
+
+ $workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
+
+ $step = $workflow->get_current_step($delivery_process_entry);
+
+ if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_acceptance_action($step)) {
+
+ $action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
+
+ $action_entry = $action_entries[0];
+
+ $data[] = Wiaas_Delivery_Process_Action::get_customer_acceptance_action_data($action_entry['id']);
+ }
+ }
+
+ return empty( $data ) ? $data : $data[0];
+ }
+
+ public static function get_customer_questionnaires_data($order_id) {
+
+ $data = array();
+
+ $delivery_process_entry = self::get_order_delivery_process_entry($order_id);
+
+ if (! empty($delivery_process_entry)) {
+
+ $workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
+
+ $step = $workflow->get_current_step($delivery_process_entry);
+
+ if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_validate_questionnaires_action($step)) {
+
+ $action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
+
+ foreach ($action_entries as $action_entry) {
+
+ $action_data = Wiaas_Delivery_Process_Action::get_customer_validate_questionnaires_action_data($action_entry['id']);
+
+ if (! empty($action_data)) {
+
+ $data[] = $action_data;
+ }
+ }
+ }
+
+ }
+
+ return $data;
+ }
+
+ public static function update_customer_acceptance_status($order_id,$status, $reason) {
+
+ $delivery_process_entry = self::get_order_delivery_process_entry($order_id);
+
+ if (! empty($delivery_process_entry) ) {
+
+ $workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
+
+ $step = $workflow->get_current_step($delivery_process_entry);
+
+ $action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
+
+ $action_entry = $action_entries[0];
+
+ Wiaas_Delivery_Process_Action::update_customer_acceptance_status($action_entry['id'], $status, $reason);
+
+ if ($status === 'accept') {
+
+ Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
+ }
+ }
+ }
+
+ public static function is_customer_acceptance_uploaded($order_id) {
+
+ $delivery_process_entry = self::get_order_delivery_process_entry($order_id);
+
+ if (! empty($delivery_process_entry) ) {
+
+ $workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
+
+ $step = $workflow->get_current_step($delivery_process_entry);
+
+ $action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
+
+ $action_entry = $action_entries[0];
+
+ return Wiaas_Delivery_Process_Action::is_customer_acceptance_uploaded($action_entry['id']);
+ }
+
+ return false;
+ }
+
+ public static function upload_customer_questionnaire($order_id, $action_entry_id) {
+
+ Wiaas_Delivery_Process_Action::upload_customer_questionnaire($action_entry_id);
+
+ Wiaas_Delivery_Process_Action::complete_action_step($action_entry_id);
+ }
+
+ public static function upload_customer_acceptance_document($order_id) {
+
+ $delivery_process_entry = self::get_order_delivery_process_entry($order_id);
+
+ if (! empty($delivery_process_entry) ) {
+
+ $workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
+
+ $step = $workflow->get_current_step($delivery_process_entry);
+
+ $action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
+
+ $action_entry = $action_entries[0];
+
+ $success = Wiaas_Delivery_Process_Action::upload_customer_acceptance_document($action_entry['id']);
+
+ if ($success) {
+
+ Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
+ }
+
+ return $success;
+ }
+
+ return false;
+ }
+
+
+ public static function get_order_delivery_process_entry($order_id) {
+
+ $order = wc_get_order($order_id);
+ $process_entry_id = $order->get_meta('wiaas_delivery_process_entry_id', true);
+
+ if (!isset($process_entry_id)) {
+ return array();
+ }
+
+ return GFAPI::get_entry($process_entry_id);
+ }
+
/**
* Retrieves delivery process instance for order
*
@@ -82,9 +249,7 @@ class Wiaas_Delivery_Process {
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id');
- $process_entry_id = 159;
-
- if (!isset($process_entry_id)) {
+ if (empty($process_entry_id)) {
return null;
}
@@ -107,6 +272,11 @@ class Wiaas_Delivery_Process {
foreach ( $steps_info as $step_info ) {
$step = $api->get_step( $step_info->get_id(), $process_instance );
+ if (! $step->is_visible_to_customer) {
+
+ continue;
+ }
+
$action_code = 'manual';
$action_form = GFAPI::get_form($step->target_form_id);
$has_action_form = $action_form !== false;
@@ -141,144 +311,6 @@ class Wiaas_Delivery_Process {
return $delivery_process;
}
- public static function get_current_delivery_step_info($order_id) {
-
- $process_entry_id = 159;
-
- $process_instance = GFAPI::get_entry($process_entry_id);
- $api = new Gravity_Flow_API($process_instance['form_id']);
-
- $current_step = $api->get_current_step($process_instance);
-
- if (!$current_step) {
- return null;
- }
-
- $current_step_info = array(
- 'step_id' => $current_step->get_id(),
- 'process_id' => $process_entry_id,
- 'short_desc' => $current_step->get_name(),
- 'action_code' => 'manual',
- 'status' => $current_step->get_status(),
- );
-
- $action_form = GFAPI::get_form($current_step->target_form_id);
- $has_action_form = $action_form !== false;
- $delivery_settings = $action_form ? rgar($action_form, 'wiaas_delivery_process') : array();
-
- $customer_allowed_actions = array( 'customer-acceptance', 'validate-questionnaire' );
-
- if (! $has_action_form && ! in_array($delivery_settings['delivery_action_code'], $customer_allowed_actions)) {
-
- return $current_step_info;
- }
-
- $current_step_info['action_code'] = $delivery_settings['delivery_action_code'];
-
- $current_step_info['actions'] = array();
-
- $action_entry_ids = gform_get_meta(
- $current_step->get_entry_id(), 'wiaas_delivery_step_' . $current_step->get_id() . '_action_entry_ids'
- );
-
- if (empty($action_entry_ids)) {
- return $current_step_info;
- }
-
- $order = wc_get_order($order_id);
-
- foreach ($action_entry_ids as $action_entry_id) {
-
- $action_entry = GFAPI::get_entry($action_entry_id);
-
- if (is_wp_error($action_entry)) {
-
- continue;
- }
-
- $action_workflow_api = new Gravity_Flow_API($action_form['id']);
-
- $action_workflow_api->get_status($action_entry);
-
- $action_data = self::_collect_validate_questionnaire_action_info($action_form, $action_entry, $order);
-
- if (! empty($action_data)) {
-
- $current_step_info['actions'][] = $action_data;
- }
- }
-
- return $current_step_info;
- }
-
- /**
- * Complete action step
- *
- * @param int $action_id
- */
- public static function complete_action_step($action_id) {
-
- $action_entry = GFAPI::get_entry($action_id);
-
- $action_form = GFAPI::get_form($action_entry['form_id']);
-
- $workflow = new Gravity_Flow_API($action_form['id']);
-
- $current_step = $workflow->get_current_step($action_entry);
-
- if ( $current_step ) {
-
- $assignees = $current_step->get_assignees();
-
- foreach ($assignees as $assignee) {
-
- $current_step->process_assignee_status($assignee, 'complete', $action_form);
- }
- }
-
- gravity_flow()->process_workflow($action_form, $action_entry['id']);
- }
-
-
- private static function _collect_validate_questionnaire_action_info($action_form, $action_entry, $order) {
-
- // we need to collect document, bundle id and current status
- $bundle_item_id = null; $document_info = array(); $status = null;
-
- $bundle_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle')[0];
-
- $bundle_item_id = absint(explode('|', $action_entry[$bundle_field->id])[1]);
-
- $bundle_item = $order->get_item($bundle_item_id);
-
- $documents = wiaas_get_order_item_documents($bundle_item, 'order_questionaire');
- $document = $documents[0];
-
- $action_workflow_api = new Gravity_Flow_API($action_form['id']);
- $action_step = $action_workflow_api->get_current_step($action_entry);
- $status = 'validated';
-
- if (! empty($action_step)) {
-
- if ($action_step->get_type() === 'approval') {
-
- $status = 'not-validated';
- }
-
- if ($action_step->get_type() === 'user_input') {
-
- $status = 'invalid';
- }
- }
-
- return array(
- 'item_id' => $bundle_item_id,
- 'order_id' =>$order->get_id(),
- 'action_id' => $action_entry['id'],
- 'document' => $document,
- 'status' => $status
- );
- }
/**
* Automatically create delivery process instance when order is created
@@ -319,24 +351,3 @@ class Wiaas_Delivery_Process {
}
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );
-
-function wiaas_gform_upload_path() {
-
- $pathdata = wp_upload_dir();
-
- if ( empty( $pathdata['subdir'] ) ) {
- $pathdata['path'] = $pathdata['path'] . wiaas_documents_base_dir();
- $pathdata['url'] = $pathdata['url'] . wiaas_documents_base_dir();
- $pathdata['subdir'] = wiaas_documents_base_dir();
- } else {
- $new_subdir = wiaas_documents_base_dir() . $pathdata['subdir'];
-
- $pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
- $pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
- $pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
- }
-
- return $pathdata;
-}
-
-add_filter( 'gform_upload_path', 'wiaas_gform_upload_path', 10, 2 );
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
index b13f83b..e1d1683 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
@@ -2,15 +2,14 @@
class Wiaas_Delivery_Process_Action {
- public static function init() {
+ public static function is_action_form($form) {
+ $delivery_settings = rgar($form, 'wiaas_delivery_process');
+ return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
}
- /**
- * @param Wiaas_Delivery_Process_Step $step
- */
- public static function get_step_action_form(Wiaas_Delivery_Process_Step $step) {
+ public static function get_process_step_action_form($step) {
if (empty($step->target_form_id)) {
@@ -19,15 +18,36 @@ class Wiaas_Delivery_Process_Action {
$action_form = GFAPI::get_form($step->target_form_id);
- if (! $action_form) {
-
- return null;
- }
+ return $action_form;
}
- public static function get_step_action_entries(Wiaas_Delivery_Process_Step $step) {
+ public static function get_process_step_action_form_action_code($step) {
- $action_form = self::get_step_action_form($step);
+ $action_form = self::get_process_step_action_form($step);
+
+ if (empty($action_form)) {
+
+ return 'manual';
+ }
+
+ $delivery_settings = rgar($action_form, 'wiaas_delivery_process');
+
+ return empty($delivery_settings) ? 'manual' : $delivery_settings['delivery_action_code'];
+ }
+
+ public static function process_step_has_customer_acceptance_action($step) {
+
+ return self::get_process_step_action_form_action_code($step) === 'customer-acceptance';
+ }
+
+ public static function process_step_has_customer_validate_questionnaires_action($step) {
+
+ return self::get_process_step_action_form_action_code($step) === 'validate-questionnaire';
+ }
+
+ public static function get_process_step_action_entries(Wiaas_Delivery_Process_Step $step) {
+
+ $action_form = self::get_process_step_action_form($step);
if (!$action_form) {
@@ -35,7 +55,6 @@ class Wiaas_Delivery_Process_Action {
}
$search_criteria = array(
- 'status' => 'active',
'field_filters' => array(
array( 'key' => 'wiaas_delivery_process_id',
'value' => $step->get_entry_id()
@@ -67,18 +86,210 @@ class Wiaas_Delivery_Process_Action {
return $action_forms;
}
- public static function is_action_form($form) {
+ public static function complete_action_step($action_id) {
- $delivery_settings = rgar($form, 'wiaas_delivery_process');
+ $action_entry = GFAPI::get_entry($action_id);
- return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+ $workflow = new Gravity_Flow_API($action_form['id']);
+
+ $current_step = $workflow->get_current_step($action_entry);
+
+ if ( $current_step ) {
+
+ $new_status = $current_step->get_type() === 'approval' ? 'approved' : 'complete';
+
+ $assignees = $current_step->get_assignees();
+
+ foreach ($assignees as $assignee) {
+
+ $current_step->process_assignee_status($assignee, $new_status, $action_form);
+ }
+ }
+
+ gravity_flow()->process_workflow($action_form, $action_entry['id']);
}
- public static function get_customer_step_actions(Wiaas_Delivery_Process_Step $step) {
+ public static function upload_customer_questionnaire($action_entry_id) {
+ $action_entry = GFAPI::get_entry($action_entry_id);
+
+ $document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
+
+
+ $new_file = $document_field->get_single_file_value($action_entry['form_id'], 'file');
+
+ $action_entry[$document_field->id] = $new_file;
+
+ GFAPI::update_entry($action_entry);
+ }
+
+ public static function get_customer_acceptance_action_data($action_id) {
+
+ $action_entry = GFAPI::get_entry($action_id);
+
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+
+ $acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
+ $acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
+ $decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
+ $expiration_date_field = GFCommon::get_fields_by_type($action_form, 'date')[0];
+
+ $file_paths = json_decode($action_entry[$acceptance_documents_field->id]);
+
+ $documents = array();
+
+ foreach ($file_paths as $file_path) {
+
+ $info = pathinfo( $file_path );
+
+ $documents[] = array(
+ 'name' => $info['basename'],
+ 'url' => $acceptance_documents_field->get_download_url( $file_path, true )
+ );
+ }
+
+
+ return array(
+ 'action_id' => $action_entry['id'],
+ 'documents' => $documents,
+ 'expiration' => $action_entry[$expiration_date_field->id],
+ 'decline_reason' => $action_entry[$decline_reason_field->id],
+ 'status' => ($action_entry[$acceptance_field->id] === 'accept') ? 1 : -1
+ );
+ }
+
+ public static function is_customer_acceptance_uploaded($action_id) {
+
+ $action_entry = GFAPI::get_entry($action_id);
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+
+ $acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
+
+ return ! empty( $action_entry[$acceptance_documents_field->id]);
+ }
+
+ public static function update_customer_acceptance_status($action_id, $new_status, $reason) {
+
+ $action_entry = GFAPI::get_entry($action_id);
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+ $acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
+ $decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
+
+ $action_entry[$acceptance_field->id] = $new_status;
+ $action_entry[$decline_reason_field->id] = $reason;
+
+ GFAPI::update_entry($action_entry);
+ }
+
+ public static function upload_customer_acceptance_document($action_id) {
+
+ $action_entry = GFAPI::get_entry($action_id);
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+ $acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
+
+ $old_value = $action_entry[$acceptance_documents_field->id];
+
+ $value = $acceptance_documents_field->get_single_file_value($action_form['id'], 'file');
+
+ if ($acceptance_documents_field->multipleFiles ) {
+
+ $value = array( $value );
+
+ $old_value = json_decode( $old_value );
+
+ if (! empty($old_value)) {
+
+ $old_value = is_array( $old_value ) ? $old_value : array( $old_value );
+
+ $value = array_merge( $value, $old_value );
+ }
+
+ $value = json_encode( $value );
+ }
+
+ $action_entry[$acceptance_documents_field->id] = $value;
+
+ $result = GFAPI::update_entry($action_entry);
+
+ return ! is_wp_error($result);
+ }
+
+ public static function get_customer_validate_questionnaires_action_data($action_id) {
+
+ $action_entry = GFAPI::get_entry($action_id);
+
+ $action_form = GFAPI::get_form($action_entry['form_id']);
+
+ $order_id = $action_entry['wiaas_delivery_order_id'];
+ $order = wc_get_order($order_id);
+
+
+ // we need to collect document, bundle id and current status
+ $bundle_item_id = null; $status = null;
+
+ $bundle_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle')[0];
+ $bundle_item_id = absint(explode('|', $action_entry[$bundle_field->id])[1]);
+
+ if (empty($bundle_item_id)) {
+
+ return null;
+ }
+ $bundle_item = $order->get_item($bundle_item_id);
+
+ $document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
+ $file_path = $action_entry[$document_field->id];
+
+ $info = pathinfo( $action_entry[$document_field->id] );
+
+ $document = array(
+ 'name' => $info['basename'],
+ 'url' => $document_field->get_download_url( $file_path, true )
+ );
+
+ $discussion_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'workflow_discussion')[0];
+ $discussion_items = json_decode($action_entry[$discussion_field->id], ARRAY_A);
+
+ $formated_comments = array();
+
+ if (is_array($discussion_items)) {
+ foreach ($discussion_items as $item) {
+
+ $formated_comments[] = $discussion_field->format_discussion_item( $item, 'text', $action_id );
+ }
+ }
+
+
+ $action_workflow_api = new Gravity_Flow_API($action_form['id']);
+ $action_step = $action_workflow_api->get_current_step($action_entry);
+ $status = 'validated';
+
+ if (! empty($action_step)) {
+
+ if ($action_step->get_type() === 'approval') {
+
+ $status = 'not-validated';
+ }
+
+ if ($action_step->get_type() === 'user_input') {
+
+ $status = 'invalid';
+ }
+ }
+
+ return array(
+ 'item_id' => $bundle_item_id,
+ 'order_id' =>$order->get_id(),
+ 'action_id' => $action_entry['id'],
+ 'document' => $document,
+ 'status' => $status,
+ 'comments' => $formated_comments
+ );
}
}
-
-
-Wiaas_Delivery_Process_Action::init();
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
index 779fd98..53f5579 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
@@ -27,39 +27,42 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
public function init() {
parent::init();
-
- add_action( 'gravityflow_entry_detail', array( $this, 'display_process_steps_details' ), 10, 3 );
-
- add_action('gravityflow_title_entry_detail', array( $this, 'process_title' ), 10, 3);
-
- add_filter( 'gform_upload_path', array( $this, 'post_file_upload' ), 10, 2 );
}
public function init_ajax() {
parent::init_ajax();
add_action( 'wp_ajax_wiaas_get_action_entry', array( $this, 'ajax_get_action_entry' ) );
+
+ // this AJAX action is here and not in /admin folder because of Gravity Forms extension logic
+ add_action( 'wp_ajax_wiaas_delivery_get_form', array( $this, 'ajax_get_form' ) );
}
+ public function ajax_get_form() {
- public function post_file_upload($path_info, $form_id) {
+ $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
- $wp_uploads = wp_upload_dir();
+ $field_id = sanitize_text_field( rgget( 'field_id' ) );
- if ( empty( $wp_uploads['subdir'] ) ) {
- $path_info['path'] = $wp_uploads['path'] . wiaas_documents_base_dir();
- $path_info['url'] = $wp_uploads['url'] . wiaas_documents_base_dir();
- $path_info['subdir'] = wiaas_documents_base_dir();
- } else {
- $new_subdir = wiaas_documents_base_dir() . $wp_uploads['subdir'];
+ $entry_id = absint( rgget( 'entry_id' ) );
- $path_info['path'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['path'] );
- $path_info['url'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['url'] );
- $path_info['subdir'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['subdir'] );
- }
+ $field_values = array( $field_id => $entry_id );
- error_log($path_info);
+ gravity_form_enqueue_scripts( $form_id, true );
- return $path_info;
+ $is_admin = isset( $_GET['is_admin'] );
+ if ( $is_admin ) {
+ wp_enqueue_style( 'common', site_url() . '/wp-admin/css/common.css', array(), $this->_version );
+ } else {
+ wp_enqueue_style( 'common', get_stylesheet_directory_uri() . '/style.css', array(), $this->_version );
+ }
+
+ wp_print_styles();
+ wp_print_scripts();
+ // Render an AJAX-enabled form.
+ // https://www.gravityhelp.com/documentation/article/embedding-a-form/#function-call
+ $html = gravity_form( $form_id, true, false, false, $field_values, true, 1, false );
+ printf( "%s
", $html );
+ die();
}
@@ -125,170 +128,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
return '';
}
- public function display_process_steps_details($form, $entry, $current_step) {
-
- $delivery_settings = rgar($form, 'wiaas_delivery_process');
-
- if ($delivery_settings['delivery_form_type'] === 'action') {
- return;
- }
-
- $workflow_api = new Gravity_Flow_API($form['id']);
-
- $steps = $workflow_api->get_steps();
-
- foreach ($steps as $index => $step) {
-
- if (! $step->is_active()) {
- continue;
- }
-
- $is_step_running = $step->get_status() === 'pending';
- $is_current_step = $step->get_id() === $current_step->get_id();
-
- $disabled_style = $is_step_running ? '' : 'opacity: 0.5';
-
- ?>
-
-
-
-
- get_name(), 'wiaas') ?>
-
-
- target_form_id );
-
- if (empty($action_form)) {
-
- echo '';
-
- continue;
- }
-
- $action_delivery_settings = rgar($action_form, 'wiaas_delivery_process');
-
- ?>
-
-
-
-
-
- ' .
- ' ' . $action_form['title'] . '',
- $form_url );
-
- echo $form_link;
- }
-
- echo '
';
-
- $page_size = 20;
- $search_criteria = array(
- 'status' => 'active',
- 'field_filters' => array(
- array( 'key' => 'wiaas_delivery_process_id',
- 'value' => $entry['id']
- ),
- ),
- );
- $sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
- $paging = array( 'offset' => 0, 'page_size' => $page_size );
-
- $entries = GFAPI::get_entries( $action_form, $search_criteria, $sorting, $paging );
-
- foreach ($entries as $action_entry) {
- $this->_display_step_action_entry($action_form, $action_entry);
- }
-
- ?>
-
-
-
-
-
-
-
-
- get_current_step($action_entry);
-
-
- ?>
-
-
- type === 'wiaas_order') {
- continue;
- }
-
- if ($field->type === 'workflow_discussion') {
-
- echo '| ' . $field->get_value_entry_detail($action_entry[$field->id]) . ' |
';
-
- continue;
- }
-
- $value = $field->get_value_entry_detail($action_entry[$field->id]);
- $label = $field->get_field_label(false, $action_entry[$field->id]);
-
- echo '' .
- '| ' . $label . ' : | ' .
- '' . $value . ' | ' .
- '
';
- }
-
- if (! empty($current_action_step)) {
-
- ?>
-
-
-
- |
-
- View
- get_status_label($current_action_step->get_status()) ?>
-
- |
-
-
-
-
-
-
-
- esc_html__( 'Delivery Process', 'wiaas' ),
'fields' => array(
array(
- 'name' => 'delivery_form_type',
+ 'name' => 'delivery_process',
'label' => esc_html__( 'Delivery Form Type', 'wiaas' ),
- 'type' => 'delivery_form_type',
- ),
- array(
- 'name' => 'delivery_action_code',
- 'label' => esc_html__( 'Action code', 'wiaas' ),
- 'type' => 'delivery_action_code',
- ),
- array(
- 'name' => 'delivery_action_form_type',
- 'label' => esc_html__( 'Automatic?', 'wiaas' ),
- 'type' => 'delivery_action_form_automatic',
+ 'type' => 'delivery_process',
)
)
)
);
}
- public function settings_delivery_form_type() {
+ public function settings_delivery_process() {
$this->settings_select(array(
'name' => 'delivery_form_type',
'choices' => array(
+ array( 'value' => 'process', 'label' => 'Process Form' ),
array( 'value' => 'action', 'label' => 'Action Form' ),
- array( 'value' => 'process', 'label' => 'Process Form' )
),
'after_select' => ' Choose if this form will be used as process form or action form.
' .
' Process form defines order delivery process workflow.
' .
' Action form defines custom order data that is collected from delivery process participants.
'
));
- }
- public function settings_delivery_action_code() {
- $this->settings_select(array(
- 'name' => 'delivery_action_code',
- 'choices' => array(
- array( 'value' => '', 'label' => 'Select action code ...' ),
- array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
- array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
- array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' )
- ),
- 'after_select' => ' Choose action code for action form.
'
- ));
- }
- public function settings_delivery_action_form_automatic() {
+ ?>
+
+ settings_checkbox_and_select(array(
- 'checkbox' => array(
- 'label' => esc_html__( 'Enable', 'wiaas' ),
- 'name' => 'automatic_action_entries_enabled',
- 'defeault_value' => '0',
- ),
- 'select' => array(
- 'name' => 'automatic_action_entries_type',
+
+ $settings = $this->get_current_settings();
+
+ if ($settings['delivery_form_type'] !== 'process') {
+
+ $this->settings_select(array(
+ 'name' => 'delivery_action_code',
'choices' => array(
- array(
- 'value' => 'single',
- 'label' => esc_html__( 'Single entry', 'wiaas' ),
- ),
- array(
- 'value' => 'bundle',
- 'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
- )
+ array( 'value' => '', 'label' => 'Select action code ...' ),
+ array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
+ array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
+ array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' )
),
- 'after_select' => 'Automatic entries can be created once per order or per every bundle in order.
' .
- 'Automatic entry will not be created if any required field cannot be populated.
',
- )
+ 'after_select' => ' Choose action code for action form.
'
+ ));
+
+
+ $this->settings_checkbox_and_select(array(
+ 'checkbox' => array(
+ 'label' => esc_html__( 'Automatic', 'wiaas' ),
+ 'name' => 'automatic_action_entries_enabled',
+ 'default_value' => '0',
+ ),
+ 'select' => array(
+ 'name' => 'automatic_action_entries_type',
+ 'choices' => array(
+ array(
+ 'value' => 'single',
+ 'label' => esc_html__( 'Single entry', 'wiaas' ),
+ ),
+ array(
+ 'value' => 'bundle',
+ 'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
+ )
+ ),
+ 'after_select' => 'Automatic entries can be created once per order or per every bundle in order.
' .
+ 'Automatic entry will not be created if any required field cannot be populated.
',
+ )
+ ));
+
+ return;
+ }
+
+
+ $this->settings_select(array(
+ 'name' => 'delivery_country',
+ 'choices' => array(
+ array( 'value' => 'se', 'label' => 'Sweden' ),
+ array( 'value' => 'dk', 'label' => 'Denmark' ),
+ array( 'value' => 'fi', 'label' => 'Finland' )
+ ),
+ 'after_select' => ' Choose country for which this process is defined.
'
));
}
}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
index a7f385c..5655d09 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
@@ -79,9 +79,16 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
public function update_step_status($status = false) {
- if ($status === 'cancelled') {
+ if (isset( $_POST['_gravityflow_admin_action'] ) ) {
- $status = 'complete';
+ $admin_action = rgpost( 'gravityflow_admin_action' );
+
+ list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
+
+ if ($base_admin_action === 'send_to_step' && $this->get_status() === 'pending') {
+
+ $status = 'complete';
+ }
}
parent::update_step_status($status);
@@ -262,12 +269,9 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return $action_entries_ids;
}
- $new_entry = array_merge($new_entry,array(
- 'form_id' => $this->target_form_id,
- 'wiaas_delivery_process_id' => $this->get_entry_id(),
- 'wiaas_delivery_order_id' => $order_id,
- 'wiaas_delivery_step_name' => $this->get_name(),
- ));
+ $new_entry['form_id'] = $target_form['id'];
+ $new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
+ $new_entry['wiaas_delivery_order_id'] = $order_id;
$entry_id = GFAPI::add_entry( $new_entry );
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-select.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-select.php
index 013c4df..84ddeb5 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-select.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-select.php
@@ -28,30 +28,33 @@ class Wiaas_Field_Order_Bundle_Select extends GF_Field_Select {
return $this->get_selected_bundle_display_name($value);
}
- public function get_field_input( $form, $value = '', $entry = null ) {
-
- $this->choices = array();
-
- $order_id = null;
-
- if (! empty($entry)) {
-
- $order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order' ) )[0];
-
- $order_id = ! empty($order_field) ? $entry[$order_field->id] : null;
-
- } else if( ! empty($value)) {
-
- list ($order_id, $item_id) = explode('|', $value);
- }
-
- if (! empty($order_id)) {
-
- $this->choices = $this->get_selected_bundle_display_name($order_id);
- }
-
- return parent::get_field_input( $form, $value, $entry );
- }
+// public function get_field_input( $form, $value = '', $entry = null ) {
+//
+// $this->choices = array();
+//
+// $order_id = null;
+//
+// if (! empty($entry)) {
+//
+// $order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order' ) )[0];
+//
+// $order_id = ! empty($order_field) ? $entry[$order_field->id] : null;
+//
+// } else if( ! empty($value)) {
+//
+// list ($order_id, $item_id) = explode('|', $value);
+// } else {
+//
+// $order_id = absint(rgget('order_id'));
+// }
+//
+// if (! empty($order_id)) {
+//
+// $this->choices = $this->get_selected_bundle_display_name($order_id);
+// }
+//
+// return parent::get_field_input( $form, $value, $entry );
+// }
/**
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
index 7874e74..170e576 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
@@ -65,13 +65,14 @@ class Wiaas_Order_Fields {
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
-
if (empty($form['fields']) ||
empty(GFCommon::get_fields_by_type( $form, array('wiaas_order')) ) ) {
// form does not have order field so cannot be mapped
return false;
}
+ error_log(json_encode('here'));
+
$order = wc_get_order($order_id);
$bundle_item = $order->get_item($bundle_item_id);
diff --git a/frontend/src/actions/dashboard/nextActionsActions.js b/frontend/src/actions/dashboard/nextActionsActions.js
index cfaff25..9c3ce11 100644
--- a/frontend/src/actions/dashboard/nextActionsActions.js
+++ b/frontend/src/actions/dashboard/nextActionsActions.js
@@ -19,7 +19,7 @@ export const fetchNextActions = () => {
return dispatch => {
dispatch(requestNextActions());
return client.fetch({
- url: `${API_SERVER}/wp-json/wiaas/next-delivery-steps`
+ url: `${API_SERVER}/wp-json/wiaas/delivery/next-actions`
})
.then(response => dispatch(recieveNextActions(response.data)))
.catch(error => {
diff --git a/frontend/src/actions/orders/customerAcceptanceActions.js b/frontend/src/actions/orders/customerAcceptanceActions.js
index 642a22d..7fec4e1 100644
--- a/frontend/src/actions/orders/customerAcceptanceActions.js
+++ b/frontend/src/actions/orders/customerAcceptanceActions.js
@@ -23,11 +23,11 @@ const recieveCustomerAcceptance = (json) => ({
customerAcceptance: json
});
-export const fetchCustomerAcceptance = (idEntry) => {
+export const fetchCustomerAcceptance = (idOrder) => {
return dispatch => {
dispatch(requestCustomerAcceptance());
return htmlClient.fetch({
- url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
+ url: `${API_SERVER}/wp-json/wiaas/delivery/${idOrder}/customer-acceptance`,
method: 'get'
})
.then(response => {
@@ -45,15 +45,15 @@ const uploadAcceptanceAction = () => ({
type: UPLOAD_CUSTOMER_ACCEPTANCE
});
-export const uploadAcceptance = (idEntry, file) => {
+export const uploadAcceptance = (idOrder, file) => {
return dispatch => {
dispatch(uploadAcceptanceAction());
return htmlClient.uploadFile(file, {
- url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}/upload-file`
+ url: `${API_SERVER}/wp-json/wiaas/delivery/${idOrder}/customer-acceptance/upload`
}).then(response => {
if (typeof response.data !== 'undefined') {
dispatch(updateMessages(response.data.messages, orderMessages));
- dispatch(fetchCustomerAcceptance(idEntry));
+ dispatch(fetchCustomerAcceptance(idOrder));
}
}).catch(error => {
htmlClient.onError(error, dispatch);
@@ -71,21 +71,21 @@ const sendCustomerAcceptance = () => ({
type: SEND_CUSTOMER_ACCEPTANCE
});
-export const acceptDeclineInstallation = (idEntry, actionType, declineReason) => {
+export const acceptDeclineInstallation = (idOrder, actionType, declineReason) => {
return dispatch => {
dispatch(sendCustomerAcceptance());
return htmlClient.fetch({
- url: `${API_SERVER}/wp-json/wiaas/customer-acceptance/${idEntry}`,
+ url: `${API_SERVER}/wp-json/wiaas/delivery/${idOrder}/customer-acceptance`,
method: 'post',
data: {
- actionType,
- declineReason
+ 'action_type': actionType,
+ 'decline_reason': declineReason
}
})
.then(response => {
if (response.data) {
dispatch(updateMessages(response.data.messages, orderMessages));
- dispatch(fetchCustomerAcceptance(idEntry));
+ dispatch(fetchCustomerAcceptance(idOrder));
}
})
.catch(error => {
diff --git a/frontend/src/actions/orders/customerQuestionnairesActions.js b/frontend/src/actions/orders/customerQuestionnairesActions.js
index 6fe111f..5a86e86 100644
--- a/frontend/src/actions/orders/customerQuestionnairesActions.js
+++ b/frontend/src/actions/orders/customerQuestionnairesActions.js
@@ -36,7 +36,7 @@ export const fetchCustomerQuestionnaires = (idOrder) => {
return dispatch => {
dispatch(requestCustomerQuestionnaires());
return htmlClient.fetch({
- url: `${API_SERVER}/wp-json/wiaas/customer-questionnaires/${idOrder}`,
+ url: `${API_SERVER}/wp-json/wiaas/delivery/${idOrder}/customer-questionnaires`,
method: 'get'
})
.then(response => {
@@ -55,7 +55,7 @@ export const uploadCustomerQuestionnaire = (orderId, actionId, file) => {
return dispatch => {
dispatch(uploadCustomerQuestionnaireAction());
return htmlClient.uploadFile(file, {
- url: `${API_SERVER}/wp-json/wiaas/customer-questionnaires/${orderId}/upload/${actionId}`,
+ url: `${API_SERVER}/wp-json/wiaas/delivery/${orderId}/customer-questionnaires/upload/${actionId}`,
}).then(response => {
if (typeof response.data !== 'undefined') {
dispatch(updateMessages(response.data.messages, orderMessages));
diff --git a/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx b/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
index 4d12479..300e20c 100644
--- a/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
+++ b/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
@@ -31,10 +31,10 @@ class CustomerAcceptance extends Component {
fileHandler.download(fileUrl, fileName);
}
- uploadFile(idEntry, acceptedFiles, rejectedFiles) {
+ uploadFile(idOrder, acceptedFiles, rejectedFiles) {
if(acceptedFiles && acceptedFiles.length){
const file = acceptedFiles[0];
- this.props.dispatch(uploadAcceptance(idEntry, file));
+ this.props.dispatch(uploadAcceptance(idOrder, file));
}
if(rejectedFiles && rejectedFiles.length) {
@@ -59,9 +59,9 @@ class CustomerAcceptance extends Component {
}
acceptDeclineInstallation() {
- const {idProcess} = this.props.step;
+ const {idOrder} = this.props.step;
const {actionType, reason} = this.state;
- this.props.dispatch(acceptDeclineInstallation(idProcess, actionType, reason));
+ this.props.dispatch(acceptDeclineInstallation(idOrder, actionType, reason));
this.setState({reason: ''});
}
@@ -107,8 +107,8 @@ class CustomerAcceptance extends Component {
}
componentDidMount(){
- const {idProcess} = this.props.step;
- this.props.dispatch(fetchCustomerAcceptance(idProcess));
+ const {idOrder} = this.props.step;
+ this.props.dispatch(fetchCustomerAcceptance(idOrder));
}
render() {
@@ -137,7 +137,7 @@ class CustomerAcceptance extends Component {
multiple={false}
accept=".pdf,.docx,.doc,.xlsx,.xls,.odt,.ods,.jpg,.png,.jpeg"
activeClassName="upload-file-accept"
- onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(step.idProcess, acceptedFiles, rejectedFiles)}}>
+ onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(step.idOrder, acceptedFiles, rejectedFiles)}}>
{orderTexts.labels.UPLOAD_ACCEPTANCE_LABEL}
@@ -148,7 +148,7 @@ class CustomerAcceptance extends Component {
{
customerAcceptance.documents.map((document, index) =>
- {document.name} ({document.extension})
+ {document.name}
{document.validation}
diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
index 29e09a3..63324b2 100644
--- a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
+++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
@@ -23,8 +23,8 @@ class ValidateQuestionnaire extends Component {
return (
{
- customerQuestionnaires && customerQuestionnaires.actions &&
- customerQuestionnaires.actions.map((customerQuestionnaryAction) =>
+ customerQuestionnaires &&
+ customerQuestionnaires.map((customerQuestionnaryAction) =>
-
{this.downloadDocument(document)}}>
- {document.version}
+
+ {document.name}
@@ -60,8 +59,7 @@ class ValidateQuestionnaireItem extends Component {
(action.comments && action.comments.length > 0) &&
{action.comments.map((comment, key) =>
-
{comment.user} - {comment.addDate}
-
{comment.comment}
+
{comment}
)}
}
@@ -80,9 +78,8 @@ class ValidateQuestionnaireItem extends Component {
:
- {this.downloadDocument(document)}}>
- {document.version}
+
+ {document.name}
diff --git a/frontend/src/helpers/OrderHelper.js b/frontend/src/helpers/OrderHelper.js
index 1b585c3..409405d 100644
--- a/frontend/src/helpers/OrderHelper.js
+++ b/frontend/src/helpers/OrderHelper.js
@@ -11,10 +11,15 @@ function formatAddress(addressObject) {
}
export const fromWCOrder = (WCOrder) => {
- let processInfo = Object.assign({},WCOrder['delivery-process']);
- if (WCOrder['delivery-process']){
+ let processInfo = undefined;
+
+ if (WCOrder['delivery-process']) {
+
+ processInfo = Object.assign({},WCOrder['delivery-process']);
processInfo.steps = WCOrder['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
+
}
+
return {
id: WCOrder.id,
number: WCOrder.number,