delivery step actions

This commit is contained in:
Almira Krdzic
2018-10-30 17:20:56 +01:00
parent f5766cda99
commit 5aca4e8572
23 changed files with 1651 additions and 218 deletions

View File

@@ -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);
}
});

View File

@@ -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<order_id>\d+)', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_customer_questionnaires'),
//'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer-questionnaires/(?P<order_id>\d+)/upload/(?P<action_id>\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);
}

View File

@@ -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 );

View File

@@ -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'));

View File

@@ -0,0 +1,38 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Dates_List_Field extends GF_Field_List {
public $type = 'wiaas_date_list';
public function get_form_editor_field_title() {
return esc_attr__( 'Date List', 'wiaas' );
}
public function sanitize_settings() {
parent::sanitize_settings();
//$this->inputType = 'date';
}
public function get_list_input($has_columns, $column, $value, $form_id) {
$tabindex = $this->get_tabindex();
$disabled = $this->is_form_editor() ? 'disabled' : '';
return "<input type='date' name='input_{$this->id}[]' value='" . esc_attr( $value ) . "' {$tabindex} {$disabled}/>";
}
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() );

View File

@@ -0,0 +1,84 @@
<?php
class Wiaas_Delivery_Process_Action {
public static function init() {
}
/**
* @param Wiaas_Delivery_Process_Step $step
*/
public static function get_step_action_form(Wiaas_Delivery_Process_Step $step) {
if (empty($step->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();

View File

@@ -0,0 +1,420 @@
<?php
if (! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
private static $_instance = null;
protected $_slug = 'wiaas_delivery_process';
protected $_title = 'Delivery Process';
protected $_short_title = 'Delivery Process';
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new Wiaas_Delivery_Process_Addon();
}
return self::$_instance;
}
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' ) );
}
public function post_file_upload($path_info, $form_id) {
$wp_uploads = wp_upload_dir();
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'];
$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'] );
}
error_log($path_info);
return $path_info;
}
public function ajax_get_action_entry() {
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
$entry_id = absint( rgget( 'entry_id' ) );
}
/**
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
*
* @param array $entry_meta
* @param int $form_id
*
* @return array
*/
public function get_entry_meta( $entry_meta, $form_id ) {
$entry_meta[ 'wiaas_delivery_process_id' ] = array(
'label' => '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';
?>
<div class="postbox" style="<?php esc_attr_e($disabled_style, 'wiaas') ?>">
<h3>
<span><?php esc_html_e($step->get_name(), 'wiaas') ?></span>
</h3>
<?php
if ($is_current_step) {
Gravity_Flow_Entry_Detail::maybe_show_instructions(true, true, $current_step, $form, $entry);
$action_form = GFAPI::get_form( $step->target_form_id );
if (empty($action_form)) {
echo '</div>';
continue;
}
$action_delivery_settings = rgar($action_form, 'wiaas_delivery_process');
?>
<div class="submitbox" style="padding: 10px;">
<table>
<tbody>
<?php
if (! $action_delivery_settings['automatic_action_entries_enabled']) {
$form_url = admin_url( 'admin-ajax.php' ) . '?action=gravityflowparentchild_get_form&order_id=65&form_id=' . $action_form['id'] . '&wiaas_delivery_process_id=' . $entry['id'];
$form_url .= '&is_admin=1';
$form_link = sprintf(
'<a href="%s&TB_iframe=true&width=600&height=550" class="button button-primary thickbox">' .
'<i class="fa fa-plus"></i> ' . $action_form['title'] . '</a>',
$form_url );
echo $form_link;
}
echo '<br><br><br>';
$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);
}
?>
</tbody>
</table>
</div>
<?php
}
?>
</div>
<?php
}
}
private function _display_step_action_entry($action_form, $action_entry) {
$workflow_api = new Gravity_Flow_API($action_entry['form_id']);
$current_action_step = $workflow_api->get_current_step($action_entry);
?>
<table>
<?php
foreach ($action_form['fields'] as $field) {
if ($field->type === 'wiaas_order') {
continue;
}
if ($field->type === 'workflow_discussion') {
echo '<tr><td colspan="2">' . $field->get_value_entry_detail($action_entry[$field->id]) . '</td></tr>';
continue;
}
$value = $field->get_value_entry_detail($action_entry[$field->id]);
$label = $field->get_field_label(false, $action_entry[$field->id]);
echo '<tr>' .
'<td><strong>' . $label . ' : </strong></td>' .
'<td>' . $value . '</td>' .
'</tr>';
}
if (! empty($current_action_step)) {
?>
<tfoot>
<tr>
<td colspan="2">
<a class="button" href="<?php echo $current_action_step->get_entry_url() ?>">
View
<?php echo $current_action_step->get_status_label($current_action_step->get_status()) ?>
</a>
</td>
</tr>
</tfoot>
<?php
}
?>
</table>
<hr>
<?php
}
public function scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
$scripts = array(
array(
'handle' => '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' => '<p class="description"> Choose if this form will be used as process form or action form.</p>' .
'<p class="description"> <strong>Process form</strong> defines order delivery process workflow.</p>' .
'<p class="description"> <strong>Action form</strong> defines custom order data that is collected from delivery process participants.</p>'
));
}
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' => '<p class="description"> Choose action code for action form.</p>'
));
}
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' => '<p class="description">Automatic entries can be created once per order or per every bundle in order.</p>' .
'<p class="description">Automatic entry will not be created if any required field cannot be populated.</p>',
)
));
}
}

View File

@@ -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);
?>
<h4>Step: <?php echo $this->get_name() ?></h4>
<h4>Action: <?php echo $target_form['title'] ?></h4>
<?php
# status is complete only if target entry flow is complete
return $status === 'complete' || $status === 'approved' ? 'complete' : 'pending';
}
/**
* Expands step entry with additional metadata to track created target entry id
* Expands step entry with additional metadata to track created target actions entries id
*
* @param array $entry_meta
* @param int $form_id
*
@@ -172,7 +189,7 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
*/
public function get_entry_meta($entry_meta, $form_id) {
if ($form_id === $this->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;
}
}

View File

@@ -0,0 +1,55 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Bundle_Document extends GF_Field_FileUpload {
public $type ='wiaas_order_bundle_document';
public $wiaasDocTypeFilter = 'config';
public function get_form_editor_field_settings() {
return array(
'wiaas_doc_type_filter',
'conditional_logic_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'rules_setting',
'file_extensions_setting',
'file_size_setting',
'visibility_setting',
'description_setting',
'css_class_setting',
);
}
public function get_form_editor_field_title() {
return esc_attr__( 'Bundle Document', 'wiaas' );
}
public function get_download_url( $file, $force_download = false ) {
$upload_root = GFFormsModel::get_upload_url( $this->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() );

View File

@@ -0,0 +1,109 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Bundle_Select extends GF_Field_Select {
public $type = 'wiaas_order_bundle';
public function get_form_editor_field_title() {
return esc_attr__( 'Bundle Select', 'wiaas' );
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return $this->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() );

View File

@@ -0,0 +1,53 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Number extends GF_Field_Number {
public $type = 'wiaas_order';
function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'size_setting',
'rules_setting',
'visibility_setting',
'duplicate_setting',
'default_value_setting',
'placeholder_setting',
'description_setting',
'css_class_setting',
);
}
public function sanitize_settings() {
parent::sanitize_settings();
}
public function get_form_editor_field_title() {
return esc_attr__( 'Order Number', 'wiaas' );
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return "#100000$value";
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
return "#100000$value";
}
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
return "#100000$value";
}
}
GF_Fields::register( new Wiaas_Field_Order_Number() );

View File

@@ -0,0 +1,78 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Supplier_Select extends GF_Field_Select {
public $type = 'wiaas_order_supplier';
public function get_form_editor_field_title() {
return esc_attr__( 'Supplier Select', 'wiaas' );
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return $this->_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() );

View File

@@ -0,0 +1,139 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Order_Fields {
public static function init() {
add_action( 'gform_field_standard_settings', array( __CLASS__, 'field_settings' ) );
}
/**
* Add custom settings for form order fields
*
* @param int $position
*/
public static function field_settings( $position ) {
if ( $position === 20 ) {
// After Field description setting.
?>
<li class="wiaas_doc_type_filter field_setting">
<label for="wiaas-doc-type-filter" class="section_label">
<?php esc_html_e( 'Document Type', 'wiaas' ); ?>
</label>
<select id="wiaas-doc-type-filter" onchange="SetFieldProperty('wiaasDocTypeFilter',this.value);">
<option value="configuration"><?php esc_html_e( 'Configuration', 'wiaas' ); ?></option>
<option value="order_questionaire"><?php esc_html_e( 'Order Questionaire', 'wiaas' ); ?></option>
<option value="installation_protocol"><?php esc_html_e( 'Installation protocol', 'wiaas' ); ?></option>
<option value="customer_acceptance"><?php esc_html_e( 'Customer acceptance', 'wiaas' ); ?></option>
</select>
</li>
<?php
}
}
public static function get_value_from_order_field($entry, $field) {
switch ($field->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();

View File

@@ -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 )
);
}
/**

View File

@@ -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) {
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Retrieve order suppliers
*
* @param int|WC_Order $order
*
* @return array
*/
function wiaas_get_order_suppliers($order) {
if (is_numeric($order)) {
$order = wc_get_order($order);
}
$items = $order->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;
}

View File

@@ -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);
});
}
}

View File

@@ -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:',

View File

@@ -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 (
<div id="validate-questionnaire" className="validate-questionnaire">
{
customerDocuments &&
Object.keys(customerDocuments).map((idOrderPackagePair) =>
customerQuestionnaires && customerQuestionnaires.actions &&
customerQuestionnaires.actions.map((customerQuestionnaryAction) =>
<ValidateQuestionnaireItem
customerDocuments={customerDocuments[idOrderPackagePair]}
validationComments={validationComments && validationComments[idOrderPackagePair] ? validationComments[idOrderPackagePair] : []}
orderPackage={orderPackages.find((orderPackage)=>{ 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)}
/>
)
}
</div>
@@ -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
});

View File

@@ -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 (
<div id="validate-questionnaire" className="validate-questionnaire">
@@ -37,25 +39,27 @@ class ValidateQuestionnaireItem extends Component {
<div>
{orderPackage.packageName}
{
customerDocuments.map(document => <div key={'package-document-' + document.idDocument}>
customerDocuments.map(document => <div key={'package-document-' + document.key}>
{
document.validation === 'invalid'
action.status === 'invalid'
? <div className="package-document">
<Row>
<Col xl="7" lg="8">
<div>
<span className="document-link"
onClick={() => {this.downloadDocument(document)}}>
<i className={'fa fa-file'}></i> {document.documentName} ({document.extension}) {' '}
<i className={'fa fa-file'}></i> {document.version}
</span>
<br />
<span className="document-status">
{document.validation.replace(/-/g,' ')} <div className={'status-icon ' + document.validation}></div>
{action.status.replace(/-/g,' ')} <div className={'status-icon ' + action.status}></div>
</span>
</div>
{
(validationComments && validationComments.length > 0) &&
(action.comments && action.comments.length > 0) &&
<div>
{validationComments.map((comment, key) => <div key={'step-comment-' + document.idDocument + '-' + key} className="step-comment">
{action.comments.map((comment, key) => <div key={'step-comment-' + document.idDocument + '-' + key} className="step-comment">
<div>{comment.user} - {comment.addDate}</div>
<div>{comment.comment}</div>
</div>)}
@@ -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)}}>
<h5 className="drop-zone-text">{orderTexts.labels.SELECT_OR_DROP}</h5>
</Dropzone>
</Col>
@@ -78,10 +82,11 @@ class ValidateQuestionnaireItem extends Component {
<Col>
<span className="document-link"
onClick={() => {this.downloadDocument(document)}}>
<i className={'fa fa-file'}></i> {document.documentName} ({document.extension}) {' '}
<i className={'fa fa-file'}></i> {document.version}
</span>
<br />
<span className="document-status">
{document.validation.replace(/-/g,' ')} <div className={'status-icon ' + document.validation}></div>
{action.status.replace(/-/g,' ')} <div className={'status-icon ' + action.status}></div>
</span>
</Col>
</Row>

View File

@@ -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]);

View File

@@ -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,
}
};

View File

@@ -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