Merge branch 'schedule-installation-new' into 'master'
Schedule installation See merge request saburly/wiaas/new-wiaas!49
This commit was merged in pull request #49.
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
.delivery-process {
|
||||||
|
background-color: #777;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 18px;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
text-align: left;
|
||||||
|
outline: none;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delivery-process:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
jQuery(document).ready(function($) {
|
||||||
|
|
||||||
|
$('#delivery-process-selector').change(function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_create_order_delivery_process',
|
||||||
|
_ajax_nonce: $('#wiaas_create_order_delivery_process_nonce').val(),
|
||||||
|
order: $('#wiaas_order_id').val(),
|
||||||
|
form: e.target.value
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
$.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Admin_Delivery_Process {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-flow.php';
|
||||||
|
require_once dirname( __FILE__ ) . '/delivery-process/wiaas-admin-delivery-process-ajax.php';
|
||||||
|
|
||||||
|
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function enqueue_scripts() {
|
||||||
|
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||||
|
|
||||||
|
wp_enqueue_script( 'wiaas_delivery_process', $plugin_url . '/assets/js/wiaas-admin-delivery-process.js' );
|
||||||
|
|
||||||
|
wp_enqueue_style( 'wiaas_admin_delivery_process', $plugin_url . '/assets/css/wiaas-admin-delivery-process.css' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Delivery_Process::init();
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Admin_Order_Process_Flow {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_action('woocommerce_admin_order_data_after_order_details', array(__CLASS__, 'add_custom_fields_after_order_details'), 10, 1 );
|
||||||
|
add_action('add_meta_boxes', array(__CLASS__, 'create_process_flow_meta_box'), 100);
|
||||||
|
add_action('gravityflow_entry_detail', array(__CLASS__, 'add_delivery_dates_box'), 11, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create_process_flow_meta_box(){
|
||||||
|
add_meta_box(
|
||||||
|
'order_process_flow_meta_box',
|
||||||
|
__('Order Process Flow', 'cmb'),
|
||||||
|
'Wiaas_Admin_Order_Process_Flow::add_process_flow_meta_box',
|
||||||
|
'shop_order',
|
||||||
|
'normal',
|
||||||
|
'high'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add_delivery_dates_box($form, $entry, $current_step){
|
||||||
|
$order_id = $entry['wiaas_delivery_order_id'];
|
||||||
|
|
||||||
|
$suppliers = Wiaas_Order::get_suppliers($order_id);
|
||||||
|
$final_estimated_date = Wiaas_Order::get_final_estimated_date($order_id);
|
||||||
|
$final_confirmed_date = Wiaas_Order::get_final_confirmed_date($order_id);
|
||||||
|
$earliest_installation_date = Wiaas_Order::get_earliest_installation_date($order_id);
|
||||||
|
|
||||||
|
require 'views/html-order-suppliers-delivery-dates.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add_process_flow_meta_box(){
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$order_id = $post->ID;
|
||||||
|
|
||||||
|
$process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
|
||||||
|
|
||||||
|
if ($process === NULL){
|
||||||
|
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_delivery_processes();
|
||||||
|
|
||||||
|
echo '<div>
|
||||||
|
<h1>Please select a process for the order:</h1>
|
||||||
|
<br/>
|
||||||
|
<select id="delivery-process-selector">
|
||||||
|
<option value="" disabled selected>Select ... </option>';
|
||||||
|
|
||||||
|
foreach($list_of_delivery_processes as $index => $process){
|
||||||
|
echo '<option value=' . $process['id'] . '>' . $process['title'] . '</option>';
|
||||||
|
}
|
||||||
|
echo '</select>
|
||||||
|
</div>';
|
||||||
|
wp_nonce_field( 'wiaas_create_order_delivery_process', 'wiaas_create_order_delivery_process_nonce' );
|
||||||
|
echo '<input type="hidden" id="wiaas_order_id" name="wiaas_order_id" value="' . $order_id . '"/>';
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$current_step = Wiaas_Delivery_Process::get_active_step($order_id);
|
||||||
|
$workflow_url = $current_step->get_entry_url();
|
||||||
|
|
||||||
|
echo '<div>
|
||||||
|
<a href=' . $workflow_url . '>Go to delivery process page</a>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add_custom_fields_after_order_details($order){
|
||||||
|
$order_estimated_delivery_date = Wiaas_Order::get_order_estimated_date($order->id);
|
||||||
|
|
||||||
|
$order_id = $order->id;
|
||||||
|
require 'views/html-order-delivery-date.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Order_Process_Flow::init();
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<p class="form-field form-field-wide">
|
||||||
|
<label for="estimated-delivery-date">Estimated delivery date:</label>
|
||||||
|
<input id="estimated-delivery-date" name="estimated-delivery-date"
|
||||||
|
type="date" value="<?php echo $order_estimated_delivery_date ? date("Y-m-d", $order_estimated_delivery_date) : ""; ?>"
|
||||||
|
onChange="onOrderEstimatedDeliveryDateChange(this.value)"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function onOrderEstimatedDeliveryDateChange(date) {
|
||||||
|
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||||
|
|
||||||
|
if (isNaN(timestamp)){
|
||||||
|
timestamp = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_save_estimated_date_for_order',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_estimated_date_for_order" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
date: timestamp
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
$.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div style="background:white;padding:8px 10px;">
|
||||||
|
<table style="width:100%">
|
||||||
|
<tr>
|
||||||
|
<th align="left">Suppliers</th>
|
||||||
|
<th align="left">Estimated date</th>
|
||||||
|
<th align="left">Confirmed date</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5"><hr></td>
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach($suppliers as $supplier){
|
||||||
|
echo '<tr><td>' . $supplier['name'] . '</td>';
|
||||||
|
$estimated_date = $supplier['estimated_date'] ? date("Y-m-d", $supplier['estimated_date']) : "";
|
||||||
|
$confirmed_date = $supplier['confirmed_date'] ? date("Y-m-d", $supplier['confirmed_date']) : "";
|
||||||
|
|
||||||
|
?>
|
||||||
|
<td>
|
||||||
|
<input id=<?php echo 'estimate-date-' . $supplier['id'] ?> type="date" onChange="onEstimatedDeliveryDateChange(<?php echo $supplier['id'] ?>, this.value)" value="<?php echo $estimated_date ?>" />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<input id=<?php echo 'confirmed-date-' . $supplier['id'] ?> type="date" onChange="onConfirmedDeliveryDateChange(<?php echo $supplier['id'] ?>, this.value)" value="<?php echo $confirmed_date ?>" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="5"><h4>Tracking</h4></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><button id=<?php echo $supplier['id'] ?> onClick="addAdditionalTrackingInfo(event)">Add more tracking info</button></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach($supplier['tracking_info'] as $index => $tracking_info){
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td><input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_num_' . $index ?>
|
||||||
|
placeholder="Tracking number" value="<?php echo $tracking_info['number'] ?>" /></td>
|
||||||
|
<td><input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_url_' . $index ?>
|
||||||
|
placeholder="Tracking URL" value="<?php echo $tracking_info['url'] ?>" /></td>
|
||||||
|
<td><button class="dashicons-before dashicons-yes" onClick="saveTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)"></button></td>
|
||||||
|
<td><button class="dashicons-before dashicons-dismiss" onClick="deleteTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)"></button></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td colspan="5"><hr></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><h4>Final dates : </h4></td>
|
||||||
|
<td><h4><?php echo $final_estimated_date ? date('Y-m-d', $final_estimated_date) : '-' ?></h4></td>
|
||||||
|
<td><h4><?php echo $final_confirmed_date ? date('Y-m-d', $final_confirmed_date) : '-' ?></h4></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5"><hr></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><h4>Earliest installation date : </h4></td>
|
||||||
|
<td><h4><?php echo $earliest_installation_date ? date('Y-m-d', $earliest_installation_date) : '-' ?></h4></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function onEstimatedDeliveryDateChange(supplierID, date) {
|
||||||
|
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||||
|
|
||||||
|
if (isNaN(timestamp)){
|
||||||
|
timestamp = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_save_estimated_date_for_supplier',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_estimated_date_for_supplier" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
supplier: supplierID,
|
||||||
|
date: timestamp
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
jQuery.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onConfirmedDeliveryDateChange(supplierID, date) {
|
||||||
|
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||||
|
|
||||||
|
if (isNaN(timestamp)){
|
||||||
|
timestamp = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_save_confirmed_date_for_supplier',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_confirmed_date_for_supplier" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
supplier: supplierID,
|
||||||
|
date: timestamp
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
jQuery.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function addAdditionalTrackingInfo(e){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_add_additional_tracking_info_for_supplier_in_order',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_add_additional_tracking_info_for_supplier_in_order" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
supplier: e.target.id
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
jQuery.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function saveTrackingInfo(e, supplierID, index){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var tracking_num = document.getElementById('supplier_' + supplierID + '_tracking_num_' + index).value;
|
||||||
|
var tracking_url = document.getElementById('supplier_' + supplierID + '_tracking_url_' + index).value;
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_save_tracking_info',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_tracking_info" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
supplier: supplierID,
|
||||||
|
index: index,
|
||||||
|
tracking_num: tracking_num,
|
||||||
|
tracking_url: tracking_url
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
jQuery.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function deleteTrackingInfo(e, supplierID, index){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
action: 'wiaas_delete_tracking_info',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_delete_tracking_info" ) ?>',
|
||||||
|
order: '<?php echo $order_id ?>',
|
||||||
|
supplier: supplierID,
|
||||||
|
index: index
|
||||||
|
};
|
||||||
|
|
||||||
|
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||||
|
jQuery.post(ajaxurl, data, function(response) {
|
||||||
|
if (response.success){
|
||||||
|
location.reload();
|
||||||
|
}else{
|
||||||
|
alert(response.data[0].message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
add_action( 'wp_ajax_wiaas_create_order_delivery_process', 'wiaas_ajax_create_order_delivery_process' );
|
||||||
|
add_action( 'wp_ajax_wiaas_add_additional_tracking_info_for_supplier_in_order', 'wiaas_ajax_add_additional_tracking_info_for_supplier_in_order' );
|
||||||
|
add_action( 'wp_ajax_wiaas_save_tracking_info', 'wiaas_ajax_save_tracking_info');
|
||||||
|
add_action( 'wp_ajax_wiaas_delete_tracking_info', 'wiaas_ajax_delete_tracking_info');
|
||||||
|
add_action( 'wp_ajax_wiaas_save_estimated_date_for_supplier', 'wiaas_ajax_save_estimated_date_for_supplier');
|
||||||
|
add_action( 'wp_ajax_wiaas_save_confirmed_date_for_supplier', 'wiaas_ajax_save_confirmed_date_for_supplier');
|
||||||
|
add_action( 'wp_ajax_wiaas_save_estimated_date_for_order', 'wiaas_ajax_save_estimated_date_for_order');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates delivery process for order
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_create_order_delivery_process() {
|
||||||
|
check_ajax_referer('wiaas_create_order_delivery_process');
|
||||||
|
$error = new WP_Error('-1', 'Failed to create order delivery process');
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['form'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$form_id = intval( $_POST['form'] );
|
||||||
|
|
||||||
|
if (Wiaas_Delivery_Process::create_delivery_process_for_order($order_id, $form_id)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds additional tracking info for supplier in order
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_add_additional_tracking_info_for_supplier_in_order(){
|
||||||
|
check_ajax_referer('wiaas_add_additional_tracking_info_for_supplier_in_order');
|
||||||
|
$error = new WP_Error('-1', 'Failed to add additional tracking info');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['supplier'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$supplier_id = intval( $_POST['supplier'] );
|
||||||
|
|
||||||
|
if (Wiaas_Order::add_additional_tracking_info($order_id, $supplier_id)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_ajax_save_tracking_info(){
|
||||||
|
check_ajax_referer('wiaas_save_tracking_info');
|
||||||
|
$error = new WP_Error('-1', 'Failed to save tracking info');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['index'])
|
||||||
|
|| !isset($_POST['tracking_num']) || !isset($_POST['tracking_url'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$supplier_id = intval( $_POST['supplier'] );
|
||||||
|
$index = intval($_POST['index']);
|
||||||
|
$tracking_num = $_POST['tracking_num'];
|
||||||
|
$tracking_url = $_POST['tracking_url'];
|
||||||
|
|
||||||
|
if (Wiaas_Order::save_tracking_info($order_id, $supplier_id, $index, $tracking_num, $tracking_url)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_ajax_delete_tracking_info(){
|
||||||
|
check_ajax_referer('wiaas_delete_tracking_info');
|
||||||
|
$error = new WP_Error('-1', 'Failed to save tracking info');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['index'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$supplier_id = intval( $_POST['supplier'] );
|
||||||
|
$index = intval($_POST['index']);
|
||||||
|
|
||||||
|
if (Wiaas_Order::delete_tracking_info($order_id, $supplier_id, $index)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_ajax_save_estimated_date_for_supplier(){
|
||||||
|
check_ajax_referer('wiaas_save_estimated_date_for_supplier');
|
||||||
|
$error = new WP_Error('-1', 'Failed to save estimated date');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['date'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$supplier_id = intval( $_POST['supplier'] );
|
||||||
|
$date = intval($_POST['date']);
|
||||||
|
|
||||||
|
if (Wiaas_Order::save_estimated_date($order_id, $supplier_id, $date)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_ajax_save_confirmed_date_for_supplier(){
|
||||||
|
check_ajax_referer('wiaas_save_confirmed_date_for_supplier');
|
||||||
|
$error = new WP_Error('-1', 'Failed to save confirmed date');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['date'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$supplier_id = intval( $_POST['supplier'] );
|
||||||
|
$date = intval($_POST['date']);
|
||||||
|
|
||||||
|
if (Wiaas_Order::save_confirmed_date($order_id, $supplier_id, $date)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_ajax_save_estimated_date_for_order(){
|
||||||
|
check_ajax_referer('wiaas_save_estimated_date_for_order');
|
||||||
|
$error = new WP_Error('-1', 'Failed to save global estimated date for order');
|
||||||
|
|
||||||
|
if (!isset($_POST['order']) || !isset($_POST['date'])){
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
|
$order_id = intval( $_POST['order'] );
|
||||||
|
$date = intval($_POST['date']);
|
||||||
|
|
||||||
|
if (Wiaas_Order::save_order_estimated_date($order_id, $date)){
|
||||||
|
wp_send_json_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_send_json_error($error);
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ class Wiaas_Admin {
|
|||||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
||||||
// Admin organization interface
|
// Admin organization interface
|
||||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
|
||||||
|
// Admin order delivery process
|
||||||
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
|
||||||
|
|
||||||
|
|||||||
@@ -429,6 +429,57 @@ class Wiaas_Cart {
|
|||||||
$shop_owner_id = absint($shop_owner_id);
|
$shop_owner_id = absint($shop_owner_id);
|
||||||
|
|
||||||
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
||||||
|
|
||||||
|
|
||||||
|
// add suppliers to order
|
||||||
|
$suppliers = array();
|
||||||
|
$items = $order->get_items('line_item');
|
||||||
|
|
||||||
|
foreach($items as $item){
|
||||||
|
$product = wc_get_product($item['product_id']);
|
||||||
|
|
||||||
|
if ($product->is_type('simple') && !Wiaas_Product_Category::is_installation($product)){
|
||||||
|
$supplier_id = Wiaas_Product::get_supplier_id($product->id);
|
||||||
|
$supplier_name = wiaas_get_organization_name($supplier_id);
|
||||||
|
if (!isset($suppliers[$supplier_id])){
|
||||||
|
$suppliers[$supplier_id] = array(
|
||||||
|
'id' => $supplier_id,
|
||||||
|
'name' => $supplier_name,
|
||||||
|
'estimated_date' => NULL,
|
||||||
|
'confirmed_date' => NULL,
|
||||||
|
'tracking_info' => array(),
|
||||||
|
'items' => array($product->id)
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
$suppliers[$supplier_id]['items'][] = $product->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$order->add_meta_data('_wiaas_suppliers', $suppliers, true);
|
||||||
|
|
||||||
|
// add additional date fields to order
|
||||||
|
$order->add_meta_data('_wiaas_estimated_delivery_date', NULL, true);
|
||||||
|
$order->add_meta_data('_wiaas_final_estimated_delivery_date', 0, true);
|
||||||
|
$order->add_meta_data('_wiaas_final_confirmed_delivery_date', 0, true);
|
||||||
|
$order->add_meta_data('_wiaas_earliest_installation_date', 0, true);
|
||||||
|
|
||||||
|
//add additional days prior installation field
|
||||||
|
$max_additional_days = 0;
|
||||||
|
$items = $order->get_items('line_item');
|
||||||
|
|
||||||
|
foreach($items as $item){
|
||||||
|
$product = wc_get_product($item['product_id']);
|
||||||
|
if ($product->get_type() === 'bundle'){
|
||||||
|
$package_additional_days = Wiaas_Package::get_earliest_installation_additional_days($product->id);
|
||||||
|
if ($package_additional_days > $max_additional_days){
|
||||||
|
$max_additional_days = $package_additional_days;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$order->add_meta_data('_wiaas_order_additional_days_prior_installation', $max_additional_days, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ class Wiaas_Delivery_Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static function _init_hooks() {
|
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_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_process_step'), 5, 3 );
|
||||||
|
|
||||||
@@ -80,7 +78,41 @@ class Wiaas_Delivery_Process {
|
|||||||
$order = wc_get_order($order_id);
|
$order = wc_get_order($order_id);
|
||||||
$order->update_status('completed', 'Completed order delivery process.', true);
|
$order->update_status('completed', 'Completed order delivery process.', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List available delivery processes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_available_delivery_processes(){
|
||||||
|
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
|
||||||
|
$result = array();
|
||||||
|
foreach($forms as $form){
|
||||||
|
$result[] = array(
|
||||||
|
'title' => str_replace(self::$process_form_title_prefix, '', $form->title),
|
||||||
|
'id' => $form->id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_active_step($order_id){
|
||||||
|
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id');
|
||||||
|
if (empty($process_entry_id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$process_instance = GFAPI::get_entry($process_entry_id);
|
||||||
|
$api = new Gravity_Flow_API($process_instance['form_id']);
|
||||||
|
$steps_info = $api->get_steps();
|
||||||
|
|
||||||
|
foreach ( $steps_info as $step_info ) {
|
||||||
|
return $api->get_step( $step_info->get_id(), $process_instance );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves delivery process instance for order
|
* Retrieves delivery process instance for order
|
||||||
@@ -92,7 +124,7 @@ class Wiaas_Delivery_Process {
|
|||||||
public static function get_order_delivery_process($order_id) {
|
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 = get_post_meta($order_id, 'wiaas_delivery_process_entry_id');
|
||||||
if (!isset($process_entry_id)) {
|
if (empty($process_entry_id)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,13 +164,13 @@ class Wiaas_Delivery_Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically create delivery process instance when order is created
|
* create delivery process instance
|
||||||
* @param $order_id
|
* @param $order_id
|
||||||
*/
|
*/
|
||||||
public static function create_delivery_process_for_order($order_id) {
|
public static function create_delivery_process_for_order($order_id, $form_id) {
|
||||||
$process_form = null;
|
$process_form = null;
|
||||||
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
|
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
|
||||||
$process_form = $forms[0];
|
$process_form = GFFormsModel::get_form($form_id);
|
||||||
if(isset($process_form)) {
|
if(isset($process_form)) {
|
||||||
$order = wc_get_order( $order_id );
|
$order = wc_get_order( $order_id );
|
||||||
$new_process_entry = array(
|
$new_process_entry = array(
|
||||||
@@ -150,7 +182,10 @@ class Wiaas_Delivery_Process {
|
|||||||
|
|
||||||
add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id);
|
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_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,6 +44,162 @@ class Wiaas_Order {
|
|||||||
return "1000000$number";
|
return "1000000$number";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_additional_days_prior_installation($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
return $order->get_meta('_wiaas_order_additional_days_prior_installation');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add_additional_tracking_info($order_id, $supplier_id){
|
||||||
|
$suppliers = self::get_suppliers($order_id);
|
||||||
|
foreach($suppliers as $key => $supplier){
|
||||||
|
if ($supplier['id'] === $supplier_id){
|
||||||
|
$suppliers[$key]['tracking_info'][] = array(
|
||||||
|
'number' => '',
|
||||||
|
'url' => ''
|
||||||
|
);
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||||
|
$order->save_meta_data();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function save_tracking_info($order_id, $supplier_id, $tracking_index, $tracking_num, $tracking_url){
|
||||||
|
$suppliers = self::get_suppliers($order_id);
|
||||||
|
foreach($suppliers as $key => $supplier){
|
||||||
|
if ($supplier['id'] === $supplier_id){
|
||||||
|
$suppliers[$key]['tracking_info'][$tracking_index]['number'] = $tracking_num;
|
||||||
|
$suppliers[$key]['tracking_info'][$tracking_index]['url'] = $tracking_url;
|
||||||
|
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||||
|
$order->save_meta_data();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete_tracking_info($order_id, $supplier_id, $tracking_index){
|
||||||
|
$suppliers = self::get_suppliers($order_id);
|
||||||
|
foreach($suppliers as $key => $supplier){
|
||||||
|
if ($supplier['id'] === $supplier_id){
|
||||||
|
unset($suppliers[$key]['tracking_info'][$tracking_index]);
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||||
|
$order->save_meta_data();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function save_estimated_date($order_id, $supplier_id, $date){
|
||||||
|
$suppliers = self::get_suppliers($order_id);
|
||||||
|
$updated = false;
|
||||||
|
foreach($suppliers as $key => $supplier){
|
||||||
|
if ($supplier['id'] === $supplier_id){
|
||||||
|
$suppliers[$key]['estimated_date'] = $date;
|
||||||
|
$updated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$updated){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
|
||||||
|
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||||
|
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||||
|
|
||||||
|
$order->save_meta_data();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function save_confirmed_date($order_id, $supplier_id, $date){
|
||||||
|
$suppliers = self::get_suppliers($order_id);
|
||||||
|
$updated = false;
|
||||||
|
foreach($suppliers as $key => $supplier){
|
||||||
|
if ($supplier['id'] === $supplier_id){
|
||||||
|
$suppliers[$key]['confirmed_date'] = $date;
|
||||||
|
$updated = true;
|
||||||
|
if (!$suppliers[$key]['estimated_date']){
|
||||||
|
$suppliers[$key]['estimated_date'] = $date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$updated){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
|
||||||
|
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||||
|
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||||
|
|
||||||
|
$order->save_meta_data();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_order_estimated_date($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
if (!$order){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order->get_meta('_wiaas_order_estimated_delivery_date') ?: NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function save_order_estimated_date($order_id, $date){
|
||||||
|
return update_post_meta($order_id, '_wiaas_order_estimated_delivery_date', $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_final_estimated_date($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
if (!$order){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order->get_meta('_wiaas_final_estimated_delivery_date') ?: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_final_confirmed_date($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
if (!$order){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order->get_meta('_wiaas_final_confirmed_delivery_date') ?: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_earliest_installation_date($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
if (!$order){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $order->get_meta('_wiaas_earliest_installation_date') ?: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get suppliers related to order
|
||||||
|
*/
|
||||||
|
public static function get_suppliers($order_id){
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
return $order->get_meta('_wiaas_suppliers');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update `shop_order` post type settings before creation to enable better order management for wiaas
|
* Update `shop_order` post type settings before creation to enable better order management for wiaas
|
||||||
*
|
*
|
||||||
@@ -196,6 +352,59 @@ class Wiaas_Order {
|
|||||||
* PRIVATE
|
* PRIVATE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
private static function _update_max_and_earliest_dates($order, $suppliers){
|
||||||
|
$max_estimated_date = 0;
|
||||||
|
$max_confirmed_date = 0;
|
||||||
|
$earliest_installation_date = 0;
|
||||||
|
$missing_estimated = false;
|
||||||
|
$missing_confirmed = false;
|
||||||
|
$no_earliest = false;
|
||||||
|
|
||||||
|
foreach($suppliers as $supplier){
|
||||||
|
if (!$supplier['estimated_date']){
|
||||||
|
$missing_estimated = true;
|
||||||
|
}
|
||||||
|
if (!$supplier['confirmed_date']){
|
||||||
|
$missing_confirmed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($supplier['estimated_date'] > $max_estimated_date){
|
||||||
|
$max_estimated_date = $supplier['estimated_date'];
|
||||||
|
}
|
||||||
|
if ($supplier['confirmed_date'] > $max_confirmed_date){
|
||||||
|
$max_confirmed_date = $supplier['confirmed_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$no_earliest){
|
||||||
|
$supplier_date = $supplier['estimated_date'];
|
||||||
|
if ($supplier['confirmed_date'] > $supplier_date){
|
||||||
|
$supplier_date = $supplier['confirmed_date'];
|
||||||
|
}
|
||||||
|
if ($supplier_date > 0){
|
||||||
|
if ($supplier_date > $earliest_installation_date){
|
||||||
|
$earliest_installation_date = $supplier_date;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$no_earliest = true;
|
||||||
|
$earliest_installation_date = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($missing_estimated && $missing_confirmed){
|
||||||
|
$no_earliest = true;
|
||||||
|
$earliest_installation_date = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$no_earliest){
|
||||||
|
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' days', $earliest_installation_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
|
||||||
|
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
|
||||||
|
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append specific wiaas order details, like reference
|
* Append specific wiaas order details, like reference
|
||||||
* @param $data
|
* @param $data
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ class Wiaas_Package {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_earliest_installation_additional_days($package_id){
|
||||||
|
return get_post_meta($package_id, 'additional_days_prior_earliest_installation', true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append package documents
|
* Append package documents
|
||||||
* @param $data
|
* @param $data
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ class Wiaas_Product {
|
|||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_supplier_id($product_id){
|
||||||
|
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Product::init();
|
Wiaas_Product::init();
|
||||||
@@ -46,6 +46,27 @@
|
|||||||
"load_terms": 1,
|
"load_terms": 1,
|
||||||
"return_format": "id",
|
"return_format": "id",
|
||||||
"multiple": 0
|
"multiple": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "field_5bdb1512ab14f",
|
||||||
|
"label": "Additional days prior earliest installation",
|
||||||
|
"name": "additional_days_prior_earliest_installation",
|
||||||
|
"type": "number",
|
||||||
|
"instructions": "",
|
||||||
|
"required": 0,
|
||||||
|
"conditional_logic": 0,
|
||||||
|
"wrapper": {
|
||||||
|
"width": "",
|
||||||
|
"class": "",
|
||||||
|
"id": ""
|
||||||
|
},
|
||||||
|
"default_value": 5,
|
||||||
|
"placeholder": "",
|
||||||
|
"prepend": "",
|
||||||
|
"append": "",
|
||||||
|
"min": 0,
|
||||||
|
"max": "",
|
||||||
|
"step": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"location": [
|
"location": [
|
||||||
|
|||||||
Reference in New Issue
Block a user