diff --git a/backend/app/plugins/wiaas/assets/js/wiaas-form-editor.js b/backend/app/plugins/wiaas/assets/js/wiaas-form-editor.js new file mode 100644 index 0000000..fc6ddc0 --- /dev/null +++ b/backend/app/plugins/wiaas/assets/js/wiaas-form-editor.js @@ -0,0 +1,10 @@ +jQuery(document).bind('gform_load_field_settings', function (event, field, form) { + + var isBundleDoc = field.type === 'wiaas_order_bundle_document'; + + if (isBundleDoc) { + + jQuery('#wiaas-doc-type-filter').val(field.wiaasDocTypeFilter); + } + +}); \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php index 76416f8..b510ba0 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php @@ -51,6 +51,19 @@ class Wiass_REST_Delivery_Process_API { 'callback' => array(__CLASS__, 'upload_file'), 'permission_callback' => 'is_user_logged_in' ) ); + + + register_rest_route( self::$namespace, 'customer-questionnaires/(?P\d+)', array( + 'methods' => 'GET', + 'callback' => array(__CLASS__, 'get_customer_questionnaires'), + //'permission_callback' => 'is_user_logged_in' + ) ); + + register_rest_route( self::$namespace, 'customer-questionnaires/(?P\d+)/upload/(?P\d+)', array( + 'methods' => 'POST', + 'callback' => array(__CLASS__, 'upload_customer_questionnaire'), + //'permission_callback' => 'is_user_logged_in' + ) ); } public static function get_next_actions_for_user() { @@ -97,6 +110,42 @@ class Wiass_REST_Delivery_Process_API { return rest_ensure_response($data); } + public function get_customer_questionnaires(WP_REST_Request $request) { + + $order_id = absint($request['order_id']); + + + $data = Wiaas_Delivery_Process::get_current_delivery_step_info($order_id); + + return rest_ensure_response($data); + } + + public function upload_customer_questionnaire(WP_REST_Request $request) { + + $action_id = absint($request['action_id']); + + try { + + $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) { + } + + 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)){ @@ -121,6 +170,7 @@ class Wiass_REST_Delivery_Process_API { 'extension' => $file_name_with_extension_parts[1], 'url' => $file_url ); + array_push($acceptance_documents, $acceptance_documents_entry); } 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 34b58c3..e7413c9 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php @@ -21,42 +21,31 @@ class Wiaas_Delivery_Process { private static function _init_hooks() { add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' )); - add_filter( 'gform_entry_meta', array(__CLASS__, 'extend_gravity_form_entry_meta'), 10, 2 ); - add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_process_step'), 5, 3 ); - add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 ); - - // Some temporary functions to make inbox page prettier - add_filter('gravityflow_inbox_submitter_name', array(__CLASS__, 'display_step_name_in_inbox'), 10, 3); - add_filter('gravityflow_approve_label_workflow_detail', array(__CLASS__, 'approval_step_approval_label'), 10, 2); - add_filter('gravityflow_reject_label_workflow_detail', array(__CLASS__, 'approval_step_reject_label'), 10, 2); } - public static function approval_step_approval_label($label, $step) { - if ($step->get_name() === 'Complete step') { - return esc_html__( 'Complete step', 'wiaas' ); - } - return $label; - } - - public static function approval_step_reject_label($label, $step) { - if ($step->get_name() === 'Complete step') { - return esc_html__( 'Cancel', 'wiaas' ); - } - return $label; - } - - public static function display_step_name_in_inbox($name, $entry, $form) { - return $entry['wiaas_delivery_step_name']; - } - /** * Registers our Delivery Process Step Type as available Gravity Flow Step Type */ private static function _register_delivery_process_step_type() { require_once( 'delivery-process/class-wiaas-delivery-process-step.php' ); + require_once( 'delivery-process/class-wiaas-delivery-process-addon.php' ); + + // order fields + require_once( 'delivery-process/class-wiaas-order-fields.php' ); + + require_once( 'delivery-process/class-wiaas-field-order-number.php' ); + require_once( 'delivery-process/class-wiaas-field-order-bundle-select.php' ); + require_once( 'delivery-process/class-wiaas-field-order-supplier-select.php' ); + require_once( 'delivery-process/class-wiaas-field-order-bundle-document.php' ); + + + require_once( 'delivery-process/class-wiaas-date-list-field.php' ); + Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() ); + + GFAddOn::register( 'Wiaas_Delivery_Process_Addon' ); } /** @@ -92,6 +81,9 @@ class Wiaas_Delivery_Process { public static function get_order_delivery_process($order_id) { $process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id'); + + $process_entry_id = 159; + if (!isset($process_entry_id)) { return null; } @@ -110,111 +102,241 @@ class Wiaas_Delivery_Process { 'steps' => array() ); + $current_step = $api->get_current_step($process_instance); + foreach ( $steps_info as $step_info ) { - $step = $api->get_step( $step_info->get_id(), $process_instance ); + $step = $api->get_step( $step_info->get_id(), $process_instance ); + + $action_code = 'manual'; + $action_form = GFAPI::get_form($step->target_form_id); + $has_action_form = $action_form !== false; + + if ($has_action_form) { + + $delivery_settings = rgar($action_form, 'wiaas_delivery_process'); + + $action_code = empty($delivery_settings['delivery_action_code']) ? 'manual' : $delivery_settings['delivery_action_code']; + } $info = $step->get_feed_meta(); + + $status = $step->get_status(); + + if ($current_step && $current_step->get_id() === $step->get_id()) { + $status = 'pending'; + } + + $delivery_process['steps'][] = array( 'step_id' => $step->get_id(), - 'step_form_entry_id' => $step->get_target_form_entry_id() ?: null, + 'process_id' => $process_entry_id, 'short_desc' => $info['step_name'], 'full_desc' => $info['description'], - 'action_code' => $step->get_delivery_action_type(), - 'step_type' => $step->get_delivery_action_type() === 'manual' ? 'manual' : 'extraAction', - 'status' => $step->get_status() ?: 'inactive', + 'action_code' => $action_code, + 'status' => $status, 'order_id' => $order_id, - 'actual_date' => $step->get_target_actual_date(), - 'comments' => $step->get_target_step_comments(), ); } 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 * @param $order_id */ public static function create_delivery_process_for_order($order_id) { $process_form = null; - $forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true ); - $process_form = $forms[0]; - if(isset($process_form)) { - $order = wc_get_order( $order_id ); - $new_process_entry = array( - 'form_id' => $process_form->id, - '2' => $order->get_customer_id(), - 'wiaas_delivery_order_id' => $order_id, - ); - $process_entry_id = GFAPI::add_entry( $new_process_entry ); - add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id); - add_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id); - } - } + $forms = GFAPI::get_forms(); + foreach ( $forms as $form ) { + $delivery_settings = rgar($form, 'wiaas_delivery_process'); + if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'process'){ + $process_form = $form; - /** - * Extends Gravity Form entry metadata with 'wiaas_delivery_process_id' - * - * This way we can track for each delivery step its parent process - * @param $entry_meta - * - * @return mixed - */ - public static function extend_gravity_form_entry_meta($entry_meta) { - $entry_meta[ 'wiaas_delivery_process_id' ] = array( - 'label' => 'Wiaas Delivery Process Id', - 'is_numeric' => true, - 'update_entry_meta_callback' => null, - 'is_default_column' => false, // this column will be displayed by default on the entry list - 'filter' => array( - 'operators' => array( 'is' ), - ), - ); - - $entry_meta[ 'wiaas_delivery_order_id' ] = array( - 'label' => 'Wiaas Delivery Process Order Id', - 'is_numeric' => true, - 'update_entry_meta_callback' => null, - 'is_default_column' => false, // this column will be displayed by default on the entry list - 'filter' => array( - 'operators' => array( 'is' ), - ), - ); - - $entry_meta[ 'wiaas_delivery_step_name' ] = array( - 'label' => 'Wiaas Delivery Step name', - 'is_numeric' => false, - 'update_entry_meta_callback' => null, - 'is_default_column' => false, // this column will be displayed by default on the entry list - 'filter' => array( - 'operators' => array( 'is' ), - ), - ); - - return $entry_meta; - } - - /** - * Process parent process when single step workflow has completed - * @param $entry_id - * @param $form - * @param $final_status - */ - public static function maybe_complete_parent_process_step($entry_id, $form) { - $entry = GFAPI::get_entry($entry_id); - $parent_entry_id = $entry['wiaas_delivery_process_id']; - - if (empty($parent_entry_id)) { - return false; + break; + } } - $parent_entry_id = absint( $parent_entry_id ); - $parent_entry = GFAPI::get_entry( $parent_entry_id ); + if (empty($process_form)) { - $parent_api = new Gravity_Flow_API( $parent_entry['form_id'] ); - $parent_api->process_workflow( $parent_entry_id ); + return; + } + + $order = wc_get_order( $order_id ); + $order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0]; + $order_field_id = $order_field->id; + + $new_process_entry = array( + 'form_id' => $process_form->id, + "$order_field_id" => $order_id, + 'wiaas_delivery_order_id' => $order_id, + ); + $process_entry_id = GFAPI::add_entry( $new_process_entry ); + + add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id); + add_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id); } } 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/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php index 2ae0029..084689c 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php @@ -18,6 +18,7 @@ class Wiaas_Order { public static function init() { require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php'; + require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php'; add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings')); diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-date-list-field.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-date-list-field.php new file mode 100644 index 0000000..767c08d --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-date-list-field.php @@ -0,0 +1,38 @@ +inputType = 'date'; + } + + public function get_list_input($has_columns, $column, $value, $form_id) { + + $tabindex = $this->get_tabindex(); + $disabled = $this->is_form_editor() ? 'disabled' : ''; + + return ""; + } + + public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) { + + return $this->get_value_entry_detail($value, '', false, 'html', 'screen' ); + } +} + +GF_Fields::register( new Wiaas_Dates_List_Field() ); \ No newline at end of file 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 new file mode 100644 index 0000000..b13f83b --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php @@ -0,0 +1,84 @@ +target_form_id)) { + + return null; + } + + $action_form = GFAPI::get_form($step->target_form_id); + + if (! $action_form) { + + return null; + } + } + + public static function get_step_action_entries(Wiaas_Delivery_Process_Step $step) { + + $action_form = self::get_step_action_form($step); + + if (!$action_form) { + + return array(); + } + + $search_criteria = array( + 'status' => 'active', + 'field_filters' => array( + array( 'key' => 'wiaas_delivery_process_id', + 'value' => $step->get_entry_id() + ), + ), + ); + + $sorting = array( 'key' => 'date_created', 'direction' => 'DESC' ); + + return GFAPI::get_entries( $action_form, $search_criteria, $sorting ); + } + + public static function get_action_forms() { + + $forms = GFAPI::get_forms(); + + $action_forms = array(); + + foreach ( $forms as $form ) { + + $delivery_settings = rgar($form, 'wiaas_delivery_process'); + + if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action'){ + + $action_forms[] = $form; + } + } + + return $action_forms; + } + + public static function is_action_form($form) { + + $delivery_settings = rgar($form, 'wiaas_delivery_process'); + + return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action'; + } + + public static function get_customer_step_actions(Wiaas_Delivery_Process_Step $step) { + + + } +} + + +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 new file mode 100644 index 0000000..779fd98 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php @@ -0,0 +1,420 @@ + 'Wiaas Delivery Process Id', + 'is_numeric' => true, + 'update_entry_meta_callback' => array( __CLASS__, 'update_entry_delivery_process_id' ), + 'is_default_column' => false, // this column will be displayed by default on the entry list + 'filter' => array( + 'operators' => array( 'is' ), + ), + ); + + $entry_meta[ 'wiaas_delivery_order_id' ] = array( + 'label' => 'Wiaas Delivery Process Order Id', + 'is_numeric' => true, + 'update_entry_meta_callback' => null, + 'is_default_column' => false, // this column will be displayed by default on the entry list + 'filter' => array( + 'operators' => array( 'is' ), + ), + ); + + $entry_meta[ 'wiaas_delivery_step_name' ] = array( + 'label' => 'Wiaas Delivery Step name', + 'is_numeric' => false, + 'update_entry_meta_callback' => null, + 'is_default_column' => false, // this column will be displayed by default on the entry list + 'filter' => array( + 'operators' => array( 'is' ), + ), + ); + + return $entry_meta; + } + + public static function update_entry_delivery_process_id($key, $entry, $form) { + + if ( isset( $_REQUEST['wiaas_delivery_process_id'] ) ) { + return absint( $_REQUEST['wiaas_delivery_process_id'] ); + } + + if ( isset( $entry[ $key ] ) ) { + return $entry[ $key ]; + } + + 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 ''; + + continue; + } + + $value = $field->get_value_entry_detail($action_entry[$field->id]); + $label = $field->get_field_label(false, $action_entry[$field->id]); + + echo '' . + '' . + '' . + ''; + } + + if (! empty($current_action_step)) { + + ?> + + + + + + + + +
' . $field->get_value_entry_detail($action_entry[$field->id]) . '
' . $label . ' : ' . $value . '
+ + View + get_status_label($current_action_step->get_status()) ?> + +
+ +
+ 'wiaas_form_editor_js', + 'src' => $plugin_url . '/assets/js/wiaas-form-editor.js', + 'enqueue' => array( + array( + 'admin_page' => array('form_editor'), + ), + ), + ) + ); + + return array_merge( parent::scripts(), $scripts ); + } + + + /** + * Add settings menu for form delivery process + * + * @param $tabs + * @param $form_id + * + * @return array + */ + public function add_form_settings_menu( $tabs, $form_id ) { + + $tabs[] = array( + 'name' => $this->_slug, + 'label' => esc_html__( 'Delivery Process', 'wiaas' ), + 'query' => array( 'fid' => null ) + ); + + return $tabs; + } + + + /** + * Add settings field for delivery process settings menu + * + * @param $form + * + * @return array + */ + public function form_settings_fields($form) { + + return array( + + array( + 'title' => esc_html__( 'Delivery Process', 'wiaas' ), + 'fields' => array( + array( + 'name' => 'delivery_form_type', + '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', + ) + ) + ) + ); + } + + public function settings_delivery_form_type() { + + $this->settings_select(array( + 'name' => 'delivery_form_type', + 'choices' => array( + 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() { + + $this->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', + '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.

', + ) + )); + } +} \ 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 8c5b478..a7f385c 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 @@ -30,7 +30,7 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { * @return string */ public function get_label() { - return esc_html__( 'Wiaas Delivery Step', 'wiaas' ); + return esc_html__( 'Delivery Step', 'wiaas' ); } /** @@ -41,13 +41,12 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { $settings_api = $this->get_common_settings_api(); - $forms = $this->get_target_forms_choices(); + $forms = $this->get_action_forms_choices(); $form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' ); foreach ( $forms as $form ) { - $form_choices[] = array( 'label' => $form->title, 'value' => $form->id ); + $form_choices[] = array( 'label' => $form['title'], 'value' => $form['id'] ); } - $settings = array( 'title' => esc_html__( 'Wiaas Delivery Step', 'wiaas' ), 'fields' => array( @@ -71,13 +70,23 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { 'type' => 'select', 'onchange' => "jQuery(this).closest('form').submit();", 'choices' => $form_choices, - ), + ) ), ); return $settings; } + public function update_step_status($status = false) { + + if ($status === 'cancelled') { + + $status = 'complete'; + } + + parent::update_step_status($status); + } + /** * Process Wiass Delivery Process Step * @@ -90,51 +99,54 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { $entry = $this->get_entry(); $target_form = GFAPI::get_form( $this->target_form_id ); - # if target form is not valid just finish the step + # if target form is not set we are done if (!$target_form) { - return true; + // return false since we wait for admin to process the step + return false; } - # create new entry for target form with populated value for customer-id from parent entry - $new_entry = array( - 'form_id' => $this->target_form_id, - 'wiaas_delivery_process_id' => $this->get_entry_id(), - 'wiaas_delivery_order_id' => $entry['wiaas_delivery_order_id'], - 'wiaas_delivery_step_name' => $this->get_name(), - ); + $delivery_settings = rgar($target_form, 'wiaas_delivery_process'); - $customer_id_value = null; + if (! $delivery_settings['automatic_action_entries_enabled']) { - if ( is_array( $form['fields'] ) ) { - foreach ( $form['fields'] as $field ) { - if (GFCommon::get_label( $field ) === 'customer-id') { - $customer_id_value = $entry[$field->id]; - break; - } - } + return false; + } + + $action_entries_ids = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids'); + + // if action entries present this step is reprocessing and we should not be creating new action entries + if (! empty($action_entries_ids)) { + // return false since we wait for admin to process the step + return false; } - if ( is_array( $target_form['fields'] ) ) { - foreach ( $target_form['fields'] as $field ) { - if (GFCommon::get_label( $field ) === 'customer-id') { - $new_entry[$field->id] = $customer_id_value; - break; - } - } + // create new entries for step action forms + $order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0]; + $order_id = empty($order_field) ? null : absint($entry[$order_field->id]); + + // if process has not order we cannot create actions + if (empty($order_id)) { + // return false since we wait for admin to process the step + return false; } - $entry_id = GFAPI::add_entry( $new_entry ); - if ( is_wp_error( $entry_id ) ) { - $this->log_debug( __METHOD__ .'(): failed to add entry' ); - } else { - // store entry id - gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id', $entry_id); + $delivery_settings = rgar($target_form, 'wiaas_delivery_process'); + + switch ($delivery_settings['automatic_action_entries_type']) { + + case 'single': + $action_entries_ids = $this->_create_single_action_entry($target_form, $order_id); + break; + case 'bundle': + $action_entries_ids = $this->_create_per_bundle_action_entries($target_form, $order_id); } + gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids', $action_entries_ids); + $note = $this->get_name() . ': ' . esc_html__( 'started.', 'wiaas' ); $this->add_note( $note ); - # return false since we wait for workflow of target entry to be complete first + // return false since we wait for admin to process the step return false; } @@ -147,24 +159,29 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { */ public function status_evaluation() { - # retrieve target form entry to check its workflow status - $target_form_entry = $this->get_target_form_entry(); + // return 'pending'; + } - # if there is no target form entry just complete the step - if(!$target_form_entry) { - return 'complete'; + public function workflow_detail_box($form, $args) { + parent::workflow_detail_box($form, $args); + + $target_form = GFAPI::get_form( $this->target_form_id ); + + if (empty( $target_form)) { + + return; } - # retrieve target form entry workflow status - $api = new Gravity_Flow_API( $this->target_form_id ); - $status = $api->get_status($target_form_entry); + ?> +

Step: get_name() ?>

+

Action:

+ get_form_id()) { - $entry_meta['wiaas_delivery_step_' . $this->get_id() .'_entry_id'] = null; + $entry_meta['wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids'] = array(); } return $entry_meta; } @@ -181,8 +198,24 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { * Retrieves forms that are valid options for delivery step action * @return array */ - public function get_target_forms_choices() { - return GFFormsModel::search_forms(self::$delivery_action_form_title_prefix, true); + public function get_action_forms_choices() { + + $forms = GFAPI::get_forms(); + + $action_forms = array(); + + foreach ( $forms as $form ) { + + $delivery_settings = rgar($form, 'wiaas_delivery_process'); + + if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action'){ + + $action_forms[] = $form; + } + } + + + return $action_forms; } /** @@ -194,37 +227,6 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { return self::$delivery_action_types[$target_form['title']]; } - public function get_target_actual_date() { - $target_entry = $this->get_target_form_entry(); - $target_form = GFAPI::get_form( $this->target_form_id ); - - if (!is_wp_error($target_entry) && is_array($target_form['fields'])) { - foreach ( $target_form['fields'] as $field ) { - if (GFCommon::get_label( $field ) === 'Actual Date') { - return $target_entry[$field->id]; - } - } - } - - return null; - } - - public function get_target_step_comments() { - $notes = RGFormsModel::get_lead_notes( $this->get_target_form_entry_id() ); - - $comments = array(); - foreach ( $notes as $key => $note ) { - if ( $note->note_type !== 'gravityflow' ) { - $comments[] = array( - 'date' => $note->date_created, - 'text' => $note->value, - 'user' => $note->user_name - ); - } - } - return $comments; - } - /** * Retrieves target form entry created when step was started * @return array|null @@ -247,4 +249,70 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { return absint($value); } + + + private function _create_single_action_entry($target_form, $order_id) { + + $action_entries_ids = array(); + + $new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form); + + if (empty($new_entry)) { + // entry cannot be created + 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(), + )); + + $entry_id = GFAPI::add_entry( $new_entry ); + + if ( is_wp_error( $entry_id ) ) { + $this->log_debug( __METHOD__ .'(): failed to add entry' ); + } else { + // store entry id + $action_entries_ids[] = $entry_id; + } + + return $action_entries_ids; + } + + + private function _create_per_bundle_action_entries($target_form, $order_id) { + + $action_entries_ids = array(); + + $bundle_items = wiaas_get_order_standard_bundle_items($order_id); + + foreach ($bundle_items as $item) { + + $new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form, $item->get_id()); + + if (empty($new_entry)) { + // entry cannot be created + continue; + } + + $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 ); + + if ( is_wp_error( $entry_id ) ) { + + $this->log_debug( __METHOD__ .'(): failed to add entry' ); + } else { + // store entry id + + $action_entries_ids[] = $entry_id; + } + } + + return $action_entries_ids; + } } diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-document.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-document.php new file mode 100644 index 0000000..08d191e --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-document.php @@ -0,0 +1,55 @@ +formId ); + $upload_root = trailingslashit( $upload_root ); + + // handle download for order documents not uploaded by gravity forms + if ( strpos( $file, $upload_root ) === false ) { + + return admin_url() . '?gf-wiaas-order-doc=' . urlencode($file); + } + + return parent::get_download_url( $file, $force_download ); + } + + public function sanitize_settings() { + parent::sanitize_settings(); + + $this->wiaasDocTypeFilter = sanitize_key($this->wiaasDocTypeFilter); + } +} + +GF_Fields::register( new Wiaas_Field_Order_Bundle_Document() ); \ No newline at end of file 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 new file mode 100644 index 0000000..013c4df --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-bundle-select.php @@ -0,0 +1,109 @@ +get_selected_bundle_display_name($value); + } + + + public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) { + return $this->get_selected_bundle_display_name($value); + } + + + public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) { + 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 ); + } + + + /** + * Adds bundles as choices + */ + public function post_convert_field() { + + if ($this->is_form_editor()) { + + $this->choices = array(); + } + + if ( ! $this->is_form_editor() && ! empty( rgget('order_id') )) { + $this->choices = $this->get_bundles_as_choices(absint(rgget('order_id'))); + } + } + + + public function get_selected_bundle_display_name($value) { + + list ($order_id, $item_id) = explode('|', $value); + + if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) { + + $item = $order->get_item($item_id); + + return $item->get_name(); + } + + return ''; + } + + + public function get_bundles_as_choices($order_id) { + + $choices = array(); + + if (! empty ($order_id) && $order = wc_get_order($order_id)) { + + $standard_bundle_items = wiaas_get_order_standard_bundle_items($order); + + foreach ($standard_bundle_items as $item) { + + $choices[] = array( + 'value' => $order_id . '|' . $item->get_id(), + 'text' => $item->get_name() + ); + } + } + + return $choices; + } +} + +GF_Fields::register( new Wiaas_Field_Order_Bundle_Select() ); diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-number.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-number.php new file mode 100644 index 0000000..fed0ead --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-field-order-number.php @@ -0,0 +1,53 @@ +_get_selected_supplier_display_name($value); + } + + + public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) { + return $this->_get_selected_supplier_display_name($value); + } + + + public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) { + return $this->_get_selected_supplier_display_name($value); + } + + + /** + * Adds bundles as choices + */ + public function post_convert_field() { + $this->choices = array(); + + if ( ! $this->is_form_editor() ) { + $this->choices = $this->_get_suppliers_as_choices(); + } + } + + + private function _get_selected_supplier_display_name($value) { + + list ($order_id, $supplier_id) = explode('|', $value); + + if (! empty($order_id) && ! empty($supplier_id) && $order = wc_get_order($order_id)) { + + return wiaas_get_organization_name($supplier_id); + } + + return ''; + } + + + private function _get_suppliers_as_choices() { + + $choices = array(); + + $order_id = absint(rgget('order_id')); + + if (! empty ($order_id) && $order = wc_get_order($order_id)) { + + $suppliers = wiaas_get_order_suppliers($order); + + foreach ($suppliers as $supplier_id => $supplier_name) { + + $choices[] = array( + 'value' => $order_id . '|' . $supplier_id, + 'text' => $supplier_name + ); + } + } + + return $choices; + } +} + +GF_Fields::register( new Wiaas_Field_Order_Supplier_Select() ); 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 new file mode 100644 index 0000000..7874e74 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php @@ -0,0 +1,139 @@ + + +
  • + + + + +
  • + + type) { + + case 'wiaas_order_bundle': + $value = $entry[$field->id]; + list ($order_id, $item_id) = explode('|', $value); + + if ( ! empty($order_id) && ! empty($item_id)) { + + return array( + 'id' => $item_id, + 'name' => $field->get_selected_bundle_display_name($value) + ); + } + + return null; + + case '': + + } + } + + + 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; + } + + $order = wc_get_order($order_id); + + $bundle_item = $order->get_item($bundle_item_id); + + $entry = array(); + + foreach ($form['fields'] as $field) { + + switch ($field->type) { + + case 'wiaas_order': + + $entry[(string) $field->id] = $order->get_id(); + + break; + + case 'wiaas_order_bundle': + + if ( empty($bundle_item) && $field->isRequired) { + // there is no data for required field so entry cannot be created + return false; + } + + if (! empty($bundle_item)) { + + $entry[(string) $field->id] = $order->get_id() . '|' . $bundle_item->get_id(); + } + + break; + + case 'wiaas_order_bundle_document': + + if ( empty($bundle_item) && $field->isRequired) { + // there is no data for required field so entry cannot be created + return false; + } + + if (! empty($bundle_item)) { + + $documents = wiaas_get_order_item_documents($bundle_item, $field->wiaasDocTypeFilter); + + if ( empty($documents) && $field->isRequired) { + // there is no data for required field so entry cannot be created + return false; + } + + if (! empty($documents)) { + + $document = $documents[0]; + + $entry[$field->id] = $document['version']; + } + } + + break; + + } + } + + return $entry; + } + +} + +Wiaas_Order_Fields::init(); diff --git a/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php b/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php index df4b6f0..916d113 100644 --- a/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php +++ b/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php @@ -12,6 +12,35 @@ class Wiaas_Document_Download { if ( isset($_GET['wiaasdoc']) ) { add_action( 'init', array( __CLASS__, 'admin_download' ) ); } + + if (isset($_GET['gf-wiaas-order-doc'])) { + + add_action( 'init', array( __CLASS__, 'admin_gf_order_document_download' ) ); + } + } + + /** + * Handle download for order documents by gravity flow steps + */ + public static function admin_gf_order_document_download() { + + if (!is_user_logged_in()) { + wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) ); + } + + // relative file path from upload dir for document + $version = urldecode($_GET['gf-wiaas-order-doc']); + + $file_path = wiaas_get_document_version_path($version); + + if (!file_exists($file_path)) { + wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) ); + } + + WC_Download_Handler::download_file_force( + $file_path, + pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION ) + ); } /** diff --git a/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php b/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php index a6d43f5..8a078ab 100644 --- a/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php +++ b/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php @@ -187,4 +187,44 @@ function wiaas_get_standard_package_order_item_documents($order, $package_item_i return $doc; }, $order_documents); +} + +/** + * Retrieve documents for order item + * + * @param $order_item + * @param string|null $doc_type + * + * @return array { + * $param string key Unique key used for frontend downloand + * $param string name Document name visible in download link + * $param string version Relative path from upload directory to physical document file + * $param string type Document type + * + * @reference Wiaas_Document + * } + */ +function wiaas_get_order_item_documents($order_item, $doc_type = null) { + + $documents = empty($order_item['wiaas_documents']) ? array() : $order_item['wiaas_documents']; + + if (empty($doc_type)) { + return $documents; + } + + $filtered_documents = array(); + + foreach ($documents as $document) { + + if ($document['type'] === $doc_type) { + $filtered_documents[] = $document; + } + } + + return $filtered_documents; +} + +function wiaas_get_order_item_document_admin_download_link($order_id, $item_id, $version) { + + } \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/order/wiaas-order-functions.php b/backend/app/plugins/wiaas/includes/order/wiaas-order-functions.php new file mode 100644 index 0000000..4132ee4 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/order/wiaas-order-functions.php @@ -0,0 +1,55 @@ +get_items(); + + $suppliers = get_terms(array( + 'taxonomy' => 'supplier', + 'fields' => 'id=>name', + 'hide_empty' => false + )); + + return $suppliers; +} + +/** + * Retrieve standard bundles from order + * + * @param int|WC_Order $order + * + * @return array + */ +function wiaas_get_order_standard_bundle_items($order) { + + if (is_numeric($order)) { + + $order = wc_get_order($order); + } + + $items = $order->get_items(); + + $standard_bundle_items = array(); + + foreach ($items as $item) { + + if (isset($item['wiaas_standard_package'])) { + + $standard_bundle_items[] = $item; + } + } + + return $standard_bundle_items; +} \ No newline at end of file diff --git a/frontend/src/actions/orders/customerQuestionnairesActions.js b/frontend/src/actions/orders/customerQuestionnairesActions.js new file mode 100644 index 0000000..6fe111f --- /dev/null +++ b/frontend/src/actions/orders/customerQuestionnairesActions.js @@ -0,0 +1,68 @@ +import { + API_SERVER +} from '../../config'; + +import { + UPLOAD_CUSTOMER_QUESTIONNAIRE, + REQUEST_CUSTOMER_QUESTIONNAIRES, + RECEIVE_CUSTOMER_QUESTIONNAIRES, + orderMessages, REQUEST_CUSTOMER_ACCEPTANCE, RECEIVE_CUSTOMER_ACCEPTANCE, UPLOAD_CUSTOMER_ACCEPTANCE +} from '../../constants/ordersConstants'; + +import { + updateMessages +} from '../notification/notificationActions'; +import HtmlClient from '../../helpers/HtmlClient'; +import {fetchCustomerAcceptance} from "./customerAcceptanceActions"; + +const htmlClient = new HtmlClient(); + + +const requestCustomerQuestionnaires = () => ({ + type: REQUEST_CUSTOMER_QUESTIONNAIRES +}); + +const receiveCustomerQuestionnaires = (json) => ({ + type: RECEIVE_CUSTOMER_QUESTIONNAIRES, + customerQuestionnaires: json +}); + +const uploadCustomerQuestionnaireAction = () => ({ + type: UPLOAD_CUSTOMER_QUESTIONNAIRE +}); + + +export const fetchCustomerQuestionnaires = (idOrder) => { + return dispatch => { + dispatch(requestCustomerQuestionnaires()); + return htmlClient.fetch({ + url: `${API_SERVER}/wp-json/wiaas/customer-questionnaires/${idOrder}`, + method: 'get' + }) + .then(response => { + if (typeof response.data !== 'undefined') { + dispatch(receiveCustomerQuestionnaires(response.data)); + } + }) + .catch(error => { + htmlClient.onError(error, dispatch); + }); + } +} + +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}`, + }).then(response => { + if (typeof response.data !== 'undefined') { + dispatch(updateMessages(response.data.messages, orderMessages)); + dispatch(fetchCustomerQuestionnaires(orderId)); + } + }).catch(error => { + htmlClient.onError(error, dispatch); + }); + } +} \ No newline at end of file diff --git a/frontend/src/constants/ordersConstants.js b/frontend/src/constants/ordersConstants.js index b2d9b2e..88fa7fc 100644 --- a/frontend/src/constants/ordersConstants.js +++ b/frontend/src/constants/ordersConstants.js @@ -46,6 +46,10 @@ export const SET_VIEW_ALL_ORDERS = MODULE + 'SET_VIEW_ALL_ORDERS'; export const REQUEST_ALL_SHIPPING_DATES_CONFIRMED = MODULE + 'REQUEST_ALL_SHIPPING_DATES_CONFIRMED'; export const RECEIVE_ALL_SHIPPING_DATES_CONFIRMED = MODULE + 'RECEIVE_ALL_SHIPPING_DATES_CONFIRMED'; +export const UPLOAD_CUSTOMER_QUESTIONNAIRE = MODULE + 'UPLOAD_CUSTOMER_QUESTIONNAIRE'; +export const REQUEST_CUSTOMER_QUESTIONNAIRES = MODULE + 'REQUEST_CUSTOMER_QUESTIONNAIRES'; +export const RECEIVE_CUSTOMER_QUESTIONNAIRES = MODULE + 'RECEIVE_CUSTOMER_QUESTIONNAIRES'; + export const orderMessages = { SYSTEM_ALLOWED_LANGUAGES_EMPTY: 'There are no languages added in the system.', ALLOWED_LANGUAGE: 'Allowed languages are:', diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx index 08cb7b5..29e09a3 100644 --- a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx +++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx @@ -1,6 +1,6 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; -import {fetchCustomerDocuments, fetchValidationComments} from '../../../../actions/orders/processActions'; +import {fetchCustomerQuestionnaires} from '../../../../actions/orders/customerQuestionnairesActions'; import ValidateQuestionnaireItem from './ValidateQuestionnaireItem.jsx'; import '../../style/ValidateQuestionnaire.css'; @@ -8,7 +8,7 @@ class ValidateQuestionnaire extends Component { componentDidMount(){ const {idOrder, idProcessStep} = this.props.step; - //this.props.dispatch(fetchCustomerDocuments(idOrder, 'orderQuestionaire')); + this.props.dispatch(fetchCustomerQuestionnaires(idOrder)); //this.props.dispatch(fetchValidationComments(idOrder, idProcessStep, 'invalidQuestionnaireComment')); } @@ -18,18 +18,18 @@ class ValidateQuestionnaire extends Component { } render() { - const {customerDocuments, validationComments, orderPackages} = this.props; + const {customerQuestionnaires, orderPackages} = this.props; return (
    { - customerDocuments && - Object.keys(customerDocuments).map((idOrderPackagePair) => + customerQuestionnaires && customerQuestionnaires.actions && + customerQuestionnaires.actions.map((customerQuestionnaryAction) => { return this.findById(orderPackage, idOrderPackagePair)})} - key={'validate-questionnaire-' + idOrderPackagePair}/> + action={customerQuestionnaryAction} + key={'validate-questionnaire-' + customerQuestionnaryAction.action_id} + orderPackage={orderPackages.find( orderPackage => orderPackage.orderItemId === customerQuestionnaryAction.item_id)} + /> ) }
    @@ -38,8 +38,7 @@ class ValidateQuestionnaire extends Component { } const mapStateToProps = (state) => ({ - customerDocuments: state.processReducer.customerDocuments, - validationComments: state.processReducer.validationComments, + customerQuestionnaires: state.processReducer.customerQuestionnaires, orderPackages: state.processReducer.orderInfo.packages }); diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx index ab6e811..568ae71 100644 --- a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx +++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx @@ -2,7 +2,7 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; import Dropzone from 'react-dropzone'; import {Row, Col} from 'reactstrap'; -import {reUploadOrderDocument, badFile} from '../../../../actions/orders/processActions'; +import {uploadCustomerQuestionnaire, badFile} from '../../../../actions/orders/customerQuestionnairesActions'; import {API_SERVER} from '../../../../config'; import FileDownloader from '../../../../helpers/FileDownloader'; import {orderTexts} from '../../../../constants/ordersConstants'; @@ -16,19 +16,21 @@ class ValidateQuestionnaireItem extends Component { fileHandler.download(fileUrl, fileName); } - uploadFile(idPackage, idOrder, idDocument,acceptedFiles, rejectedFiles) { + uploadFile(action,acceptedFiles, rejectedFiles) { if(acceptedFiles && acceptedFiles.length){ const file = acceptedFiles[0]; - this.props.dispatch(reUploadOrderDocument(idPackage, idOrder, idDocument, file)); + this.props.dispatch(uploadCustomerQuestionnaire(action.order_id, action.action_id, file)); } - if(rejectedFiles && rejectedFiles.length) { - this.props.dispatch(badFile()); - } + // if(rejectedFiles && rejectedFiles.length) { + // this.props.dispatch(badFile()); + // } } render() { - const {customerDocuments, validationComments, orderPackage} = this.props; + const {action, orderPackage} = this.props; + + const customerDocuments = [ action.document ]; return (
    @@ -37,25 +39,27 @@ class ValidateQuestionnaireItem extends Component {
    {orderPackage.packageName} { - customerDocuments.map(document =>
    + customerDocuments.map(document =>
    { - document.validation === 'invalid' + action.status === 'invalid' ?
    + {this.downloadDocument(document)}}> - {document.documentName} ({document.extension}) {' '} + {document.version} +
    - {document.validation.replace(/-/g,' ')}
    + {action.status.replace(/-/g,' ')}
    { - (validationComments && validationComments.length > 0) && + (action.comments && action.comments.length > 0) &&
    - {validationComments.map((comment, key) =>
    + {action.comments.map((comment, key) =>
    {comment.user} - {comment.addDate}
    {comment.comment}
    )} @@ -67,7 +71,7 @@ class ValidateQuestionnaireItem extends Component { multiple={false} accept=".pdf,.docx,.doc,.xlsx,.xls,.odt,.ods" activeClassName="upload-file-accept" - onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(document.idPackage, document.idOrder, document.idDocument, acceptedFiles, rejectedFiles)}}> + onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(action, acceptedFiles, rejectedFiles)}}>
    {orderTexts.labels.SELECT_OR_DROP}
    @@ -78,10 +82,11 @@ class ValidateQuestionnaireItem extends Component { {this.downloadDocument(document)}}> - {document.documentName} ({document.extension}) {' '} + {document.version} +
    - {document.validation.replace(/-/g,' ')}
    + {action.status.replace(/-/g,' ')}
    diff --git a/frontend/src/helpers/HtmlClient.js b/frontend/src/helpers/HtmlClient.js index bb9059c..31c7a6c 100644 --- a/frontend/src/helpers/HtmlClient.js +++ b/frontend/src/helpers/HtmlClient.js @@ -46,7 +46,7 @@ class HtmlClient { let formData = new FormData(); formData.append('file', file, file.name); - if(configParams) { + if(configParams && configParams.data) { Object.keys(configParams.data).forEach((paramKey) => { formData.append(paramKey, configParams.data[paramKey]); diff --git a/frontend/src/helpers/ProcessHelper.js b/frontend/src/helpers/ProcessHelper.js index 74d1c8e..4a068bb 100644 --- a/frontend/src/helpers/ProcessHelper.js +++ b/frontend/src/helpers/ProcessHelper.js @@ -3,17 +3,14 @@ import moment from "moment"; export const fromWiaasProcessStep = (step) => { return { actionCode: step.action_code, - actualDate: step.actual_date, - comments: step.comments, fullDesc: step.full_desc, idOrder: step.order_id, - idProcess: step.step_form_entry_id, //not sure about this + idProcess: step.process_id, //not sure about this idProcessStep: step.step_id, //not sure about this isNewCommentVisible: 1, //TODO : get this from backend isVisibleForCustomer: 1, //TODO : get this from backend now: moment().format("Do MMM YY"), shortDesc: step.short_desc, status: step.status, - stepType: step.step_type, } }; \ No newline at end of file diff --git a/frontend/src/reducers/orders/processReducers.js b/frontend/src/reducers/orders/processReducers.js index a240d4a..a43ca1a 100644 --- a/frontend/src/reducers/orders/processReducers.js +++ b/frontend/src/reducers/orders/processReducers.js @@ -4,6 +4,7 @@ import { RECEIVE_CUSTOMER_DOCUMENTS, RECEIVE_VALIDATION_COMMENTS, RECEIVE_CUSTOMER_ACCEPTANCE, + RECEIVE_CUSTOMER_QUESTIONNAIRES, RECEIVE_IS_COMPONENT_DISABLED, RECEIVE_IS_NEXT_STEP_WANTED, SET_EARLIEST_INSTALLATION_DATE, @@ -53,6 +54,14 @@ moduleReducers[RECEIVE_CUSTOMER_ACCEPTANCE] = (state, action) => { }); }; + +moduleReducers[RECEIVE_CUSTOMER_QUESTIONNAIRES] = (state, action) => { + + return Object.assign({}, state, { + customerQuestionnaires: action.customerQuestionnaires + }); +}; + moduleReducers[RECEIVE_IS_COMPONENT_DISABLED] = (state, action) => { const newState = {isComponentDisabled : {}}; newState.isComponentDisabled.installationScheduling = state.isComponentDisabled && state.isComponentDisabled.installationScheduling