Merge branch 'master' into order-delivery-flow
This commit is contained in:
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Order_Process_Flow {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'gravityflow_entry_detail', array( __CLASS__, 'display_process_steps_details' ), 10, 3 );
|
||||
|
||||
//add_action( 'gravityflow_title_entry_detail', array( __CLASS__, 'process_title' ), 10, 3 );
|
||||
|
||||
add_action('gravityflow_entry_detail', array(__CLASS__, 'add_delivery_dates_box'), 9, 3);
|
||||
|
||||
add_action('gravityflow_entry_detail', array(__CLASS__, 'maybe_display_delivery_process_navigation'), 9, 3);
|
||||
|
||||
add_action('gravityflow_workflow_detail_sidebar', array(__CLASS__, 'render_procurement_order_download_link'), 10, 3);
|
||||
|
||||
add_filter('gravityflow_admin_action_feedback', array(__CLASS__, 'maybe_process_admin_step_change_action'), 10, 4);
|
||||
|
||||
add_filter('gravityflow_admin_actions_workflow_detail', array(__CLASS__, 'remove_workflow_admin_actions'));
|
||||
}
|
||||
|
||||
public static function remove_workflow_admin_actions() {
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function render_procurement_order_download_link($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) ||
|
||||
Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<h3 class="hndle">
|
||||
<?php esc_html_e('Procurement report', 'wiaas') ?>
|
||||
</h3>
|
||||
<div style="padding: 10px;">
|
||||
<a
|
||||
id="wiaas_download_procurement_order_btn"
|
||||
href="<?php echo admin_url() . '?wiaas-procurement-order-id=' . $order_id ?>"
|
||||
download
|
||||
class="button"
|
||||
>
|
||||
<span><?php esc_html_e('Download procurement report', 'wiaas') ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
public static function add_delivery_dates_box($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) || Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($form['id']);
|
||||
$steps = $workflow_api->get_steps();
|
||||
|
||||
/**
|
||||
* Disable if:
|
||||
* - actions for customer config validation is not done
|
||||
* - action for customer acceptance is active or completed
|
||||
*/
|
||||
$is_disabled = false;
|
||||
foreach ($steps as $step) {
|
||||
|
||||
if (Wiaas_Delivery_Process_Action::process_step_has_customer_validate_questionnaires_action($step) &&
|
||||
$step->get_status() !== 'complete') {
|
||||
|
||||
$is_disabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Wiaas_Delivery_Process_Action::process_step_has_customer_acceptance_action($step) &&
|
||||
($step->get_id() === $current_step->get_id() || $step->get_status() === 'complete')) {
|
||||
|
||||
$is_disabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
$suppliers = wiaas_get_order_delivery_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 maybe_process_admin_step_change_action($feedback, $admin_action, $form, $entry) {
|
||||
|
||||
$admin_action = rgpost( 'wiaas_delivery_process_navigation_action' );
|
||||
|
||||
list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
if ( $base_admin_action == 'send_to_step' ) {
|
||||
$step_id = $action_id;
|
||||
$api = new Gravity_Flow_API( $form['id'] );
|
||||
$api->send_to_step( $entry, $step_id );
|
||||
$entry = GFAPI::get_entry( $entry['id'] );
|
||||
$new_step = $api->get_current_step( $entry );
|
||||
$feedback = $new_step ?
|
||||
sprintf( esc_html__( 'Sent to step: %s', 'wiaas' ), $new_step->get_name() ) :
|
||||
esc_html__( 'Workflow Complete', 'wiaas' );
|
||||
}
|
||||
|
||||
return $feedback;
|
||||
}
|
||||
|
||||
public static function maybe_display_delivery_process_navigation($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) ||
|
||||
Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$steps = gravity_flow()->get_steps($form['id'], $entry);
|
||||
|
||||
// get next step id
|
||||
$next_step = gravity_flow()->get_next_step($current_step, $entry, $form);
|
||||
$next_step_id = empty($next_step) ? null : $next_step->get_id();
|
||||
|
||||
// get previous step id
|
||||
foreach ($steps as $step) {
|
||||
|
||||
$next = gravity_flow()->get_next_step($step, $entry, $form);
|
||||
if ($next && $next->get_id() === $current_step->get_id()) {
|
||||
$previous_step = $step;
|
||||
}
|
||||
}
|
||||
$previous_step_id = empty($previous_step) ? null : $previous_step->get_id();
|
||||
|
||||
// bail out if none exist
|
||||
if ( empty($next_step_id) && empty($previous_step_id) ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @reference Gravity_Flow::maybe_process_admin_action for used field names
|
||||
* which are being checked there
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<div style="padding:10px; height:40px">
|
||||
|
||||
<input id="wiaas_delivery_process_navigation_action" type="hidden" name="wiaas_delivery_process_navigation_action">
|
||||
<input type="hidden" name="_gravityflow_admin_action" value="1">
|
||||
|
||||
<input
|
||||
data-step="send_to_step|<?php esc_attr_e($next_step_id, 'wiaas') ?>"
|
||||
type="submit"
|
||||
<?php disabled(empty($next_step_id), true, true) ?>
|
||||
class="button button-primary wiaas_delivery_step_nav"
|
||||
style="float:right; margin-left: 20px;" value="NEXT STEP">
|
||||
|
||||
<input
|
||||
data-step="send_to_step|<?php esc_attr_e($previous_step_id, 'wiaas') ?>"
|
||||
type="submit"
|
||||
<?php disabled(empty($previous_step_id), true, true) ?>
|
||||
class="button button-primary wiaas_delivery_step_nav"
|
||||
style="float:right;" value="PREV STEP">
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function display_process_steps_details($form, $entry, $current_step) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
if ($delivery_settings['delivery_form_type'] === 'action') {
|
||||
return;
|
||||
}
|
||||
|
||||
// get process order ID
|
||||
$order_id = absint($entry['wiaas_delivery_order_id']);
|
||||
|
||||
if (empty($order_id)) {
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order') )[0];
|
||||
|
||||
if ( ! empty($order_field)) {
|
||||
|
||||
$order_id = $entry[$order_field->id];
|
||||
}
|
||||
}
|
||||
|
||||
// display process steps
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($form['id']);
|
||||
|
||||
$steps = $workflow_api->get_steps();
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px;color: #34C388; "></i>
|
||||
<span>Order placed </span>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="postbox">
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px;color: #34C388; "></i>
|
||||
<span> Assign process </span>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
foreach ($steps as $index => $step) {
|
||||
|
||||
if (! $step->is_active()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_step_completed = $step->get_status() === 'complete' || $step->get_status() === 'approved';
|
||||
$is_current_step = $current_step && $step->get_id() === $current_step->get_id();
|
||||
|
||||
if ($is_current_step) {
|
||||
$style = 'color: #FD8049;';
|
||||
} else if ($is_step_completed) {
|
||||
$style = 'color: #34C388;';
|
||||
} else {
|
||||
$style = 'opacity: 0.5; color: #CCC;';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px; <?php esc_attr_e($style, 'wiaas') ?>"></i>
|
||||
<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=wiaas_delivery_get_form&order_id=' . $order_id .
|
||||
'&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) {
|
||||
self::_display_step_action_entry($action_form, $action_entry);
|
||||
}
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static 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 style="padding: 20px;"><td colspan="2">' . $field->format_discussion_value($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>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" style="text-transform: uppercase;font-size: 11px; letter-spacing: 0.4px; margin:10px;">
|
||||
<strong>
|
||||
|
||||
<?php
|
||||
if (! empty($current_action_step)) {
|
||||
echo $current_action_step->get_status_label($current_action_step->get_status()) . ': ' . $current_action_step->get_name();
|
||||
echo '<a target="_blank" href="' . $current_action_step->get_entry_url() . '">' .
|
||||
' <i class="fa fa-external-link" style="font-size: 16px;"></i>' .
|
||||
'</a>';
|
||||
|
||||
} else {
|
||||
echo $workflow_api->get_status($action_entry);
|
||||
}
|
||||
?>
|
||||
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
?>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Order_Process_Flow::init();
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Wiaas_Admin_Delivery_Process_Order {
|
||||
|
||||
public static function init() {
|
||||
|
||||
if (isset($_GET['wiaas-procurement-order-id'])) {
|
||||
|
||||
add_action('admin_init', array(__CLASS__, 'download_procurement_order'));
|
||||
}
|
||||
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'add_delivery_process_metabox'), 100 );
|
||||
|
||||
add_action('woocommerce_process_shop_order_meta', array(__CLASS__, 'maybe_assign_delivery_process'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign delivery process for order
|
||||
*
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function maybe_assign_delivery_process($order_id) {
|
||||
|
||||
if (! empty($_POST['wiaas_order_delivery_process_id'])) {
|
||||
|
||||
$process_id = absint($_POST['wiaas_order_delivery_process_id']);
|
||||
|
||||
Wiaas_Delivery_Process::create_delivery_process_for_order($order_id, $process_id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function add_delivery_process_metabox() {
|
||||
|
||||
add_meta_box(
|
||||
'order_delivery_process_meta_box',
|
||||
__('Delivery Process', 'cmb'),
|
||||
array(__CLASS__, 'order_delivery_process_meta_box'),
|
||||
'shop_order',
|
||||
'side',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
public static function order_delivery_process_meta_box() {
|
||||
|
||||
global $post;
|
||||
|
||||
$order_id = $post->ID;
|
||||
|
||||
$process_entry = Wiaas_Delivery_Process::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if ( empty($process_entry) ) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country(
|
||||
Wiaas_Countries::get_country_code_by_currency($order->get_currency())
|
||||
);
|
||||
|
||||
?>
|
||||
<div>
|
||||
<select name="wiaas_order_delivery_process_id" style="width: 100%;">
|
||||
<option value="" disabled selected>Assign process to order ... </option>
|
||||
<?php
|
||||
foreach($list_of_delivery_processes as $index => $process){
|
||||
echo '<option value=' . $process['id'] . '>' . $process['title'] . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button type="submit" class="button" style="margin-top: 10px;">Assign</button>
|
||||
</div>
|
||||
<?php
|
||||
} else{
|
||||
|
||||
$entry_url = add_query_arg( array(
|
||||
'page' => 'gravityflow-inbox',
|
||||
'view' => 'entry',
|
||||
'id' => $process_entry['form_id'],
|
||||
'lid' => $process_entry['id']
|
||||
), admin_url() );
|
||||
|
||||
?>
|
||||
<a href="<?php esc_attr_e($entry_url, 'wiaas') ?>"> Delivery Process </a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download procurement order report
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*
|
||||
*/
|
||||
public static function download_procurement_order() {
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$order_id = $_GET['wiaas-procurement-order-id'];
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
if (! $order) {
|
||||
wp_die( __( 'Invalid order.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
$organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||
$customer_organization_info = wiaas_get_organization_info($organization_id);
|
||||
|
||||
$delivery_address = $order->get_shipping_address_1() . ',' .
|
||||
$order->get_shipping_city() . ',' .
|
||||
$order->get_shipping_country() . ',' .
|
||||
$order->get_shipping_postcode();
|
||||
$billing_address = $order->get_billing_address_1() . ',' .
|
||||
$order->get_billing_city() . ',' .
|
||||
$order->get_billing_country() . ',' .
|
||||
$order->get_billing_postcode();
|
||||
|
||||
$order_procurement_info = wiaas_get_order_procurement_info($order->get_id());
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$spreadsheet->getProperties()->setCreator("RICOH")
|
||||
->setLastModifiedBy("Ricoh Dash")
|
||||
->setTitle("Order Procurement Report")
|
||||
->setSubject("Order Procurement Report")
|
||||
->setDescription("Order Procurement Report")
|
||||
->setKeywords("office 2007 openxml php order procurement")
|
||||
->setCategory("Procurement report file");
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setTitle('Order procurement');
|
||||
|
||||
$sheet->setCellValue('A1', 'Customer details');
|
||||
$sheet->setCellValue('A2', 'Name');
|
||||
$sheet->setCellValue('A3', 'Invoice address');
|
||||
$sheet->setCellValue('A4', 'Invoice Full Name');
|
||||
$sheet->setCellValue('A5', 'Invoice Email');
|
||||
$sheet->setCellValue('A6', 'VAT Number');
|
||||
|
||||
$sheet->setCellValue('B2', ! empty($customer_organization_info) ? $customer_organization_info['name'] : '');
|
||||
$sheet->setCellValue('B3', $billing_address);
|
||||
$sheet->setCellValue('B4', $order->get_formatted_billing_full_name());
|
||||
$sheet->setCellValue('B5', $order->get_billing_email());
|
||||
$sheet->setCellValue('B6', ! empty($customer_organization_info) ? $customer_organization_info['vat_code'] : '');
|
||||
|
||||
$sheet->getStyle('A1')->getFont()->setBold(true);
|
||||
|
||||
$sheet->setCellValue('A9', 'OrderDetails');
|
||||
$sheet->setCellValue('A10', 'Order number');
|
||||
$sheet->setCellValue('A11', 'Project number');
|
||||
$sheet->setCellValue('A12', 'Delivery addres');
|
||||
$sheet->setCellValue('A13', 'Delivery Full Name');
|
||||
$sheet->setCellValue('A14', 'Reference');
|
||||
$sheet->setCellValue('B10', $order->get_order_number());
|
||||
$sheet->setCellValue('B11', Wiaas_Order_Project::get_project_name_for_order($order->get_id()) );
|
||||
$sheet->setCellValue('B12', $delivery_address);
|
||||
$sheet->setCellValue('B13', $order->get_formatted_shipping_full_name());
|
||||
$sheet->setCellValue('B14', $order->get_meta('_wiaas_reference'));
|
||||
|
||||
$sheet->getStyle('A9')->getFont()->setBold(true);
|
||||
|
||||
$row = 14;
|
||||
|
||||
foreach ($order_procurement_info as $category => $products) {
|
||||
|
||||
$col = 1; $row += 2;
|
||||
|
||||
$sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
|
||||
$sheet->getStyleByColumnAndRow($col, $row)->getFont()->setBold(true);
|
||||
|
||||
$sheet->setCellValueByColumnAndRow($col, $row, ucfirst(strtolower($category)));
|
||||
|
||||
$row += 2;
|
||||
|
||||
if (! empty($products)) {
|
||||
|
||||
$product_columns = array_keys($products[0]);
|
||||
|
||||
foreach ($product_columns as $product_column_index => $product_column) {
|
||||
|
||||
$sheet->getColumnDimensionByColumn($product_column_index + 1)->setAutoSize(true);
|
||||
$sheet->getStyleByColumnAndRow($product_column_index + 1, $row)->getFont()->setBold(true);
|
||||
$sheet->setCellValueByColumnAndRow($product_column_index + 1, $row, $product_column);
|
||||
}
|
||||
}
|
||||
|
||||
$row += 1;
|
||||
foreach ($products as $product) {
|
||||
|
||||
$product_values = array_values($product);
|
||||
foreach ($product_values as $product_value_index => $product_value) {
|
||||
|
||||
$sheet->setCellValueByColumnAndRow($product_value_index + 1, $row, $product_value);
|
||||
}
|
||||
$row += 1;
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header('Content-Disposition: attachment;filename="Procurement Report '.$order->get_order_number().'.xlsx"');
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writer->save('php://output');
|
||||
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Delivery_Process_Order::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,225 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div style="margin-top: -20px;">
|
||||
<table class="widefat" disabled="disabled">
|
||||
<tr style="background: #EAF2FA;">
|
||||
<th align="left"><strong>Suppliers</strong></th>
|
||||
<th align="left"><strong>Estimated date</strong></th>
|
||||
<th align="left"><strong>Confirmed date</strong></th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($suppliers as $supplier){
|
||||
echo '<tr style="background: #f5f5f5;"><td><strong>' . $supplier['name'] . '</strong></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'] ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
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'] ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
type="date" onChange="onConfirmedDeliveryDateChange(<?php echo $supplier['id'] ?>, this.value)"
|
||||
value="<?php echo $confirmed_date ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<span>Tracking:</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
foreach($supplier['tracking_info'] as $index => $tracking_info){
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_num_' . $index ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
placeholder="Tracking number" value="<?php echo $tracking_info['number'] ?>" />
|
||||
<input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_url_' . $index ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
placeholder="Tracking URL" value="<?php echo $tracking_info['url'] ?>" />
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
onClick="saveTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)"
|
||||
value="SAVE">
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
onClick="deleteTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)" value="REMOVE"
|
||||
>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
id=<?php echo $supplier['id'] ?> onClick="addAdditionalTrackingInfo(event)"
|
||||
value="Add new tracking info">
|
||||
</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>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td><h4>Earliest installation date : </h4></td>
|
||||
<td colspan="2">
|
||||
<h4><?php echo $earliest_installation_date ? date('Y-m-d', $earliest_installation_date) : '-' ?></h4>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
</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,120 @@
|
||||
<?php
|
||||
|
||||
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');
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user