added action to calculte the order total and edit discount and total

This commit is contained in:
claudiosmweb 2014-07-18 17:24:34 -03:00
parent f3ef446678
commit e0aeacb734
7 changed files with 136 additions and 134 deletions

File diff suppressed because one or more lines are too long

View File

@ -611,12 +611,6 @@ ul.wc_coupon_list_block {
margin: 0;
line-height: 2em;
}
.cancel-action,
.save-action,
.calculate-action {
float: left;
margin-right: 2px;
}
}
.wc-order-bulk-actions {
background: #fefefe;
@ -625,7 +619,7 @@ ul.wc_coupon_list_block {
select {
vertical-align: top;
}
p.bulk_actions {
p.bulk-actions {
float: left;
}
}
@ -643,6 +637,12 @@ ul.wc_coupon_list_block {
width: 400px !important;
text-align: left;
}
.cancel-action,
.save-action,
.calculate-action {
float: left;
margin-right: 2px;
}
}
.wc-order-totals {
float: right;
@ -845,42 +845,51 @@ ul.wc_coupon_list_block {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAARklEQVQYGWP8//8/AzGACV3Rnj17/oMwujiGQnQFMD7RChlBbsRmFcwkEO3i4sJImonIumGmg0xBFifaRKIVgj2DbAUuNgCfThpracSKqwAAAABJRU5ErkJggg==) no-repeat center;
}
}
.wc-order-edit-line-item-actions {
width: 2.5em;
text-align: right;
}
}
.wc-order-items-editable {
.edit-order-item {
.ir;
display: inline-block;
margin: 0 .5em 0 0;
&:before {
.icon;
content: "\e603";
color: #999;
}
.edit-order-item {
.ir;
display: inline-block;
margin: 0 .5em 0 0;
&:hover {
&:before {
.icon;
content: "\e603";
color: #999;
}
&:hover {
&:before {
color: #555;
}
color: #555;
}
}
.delete-order-item,
.delete_refund {
.ir;
display: inline-block;
margin: 0;
}
.delete-order-item,
.delete_refund {
.ir;
display: inline-block;
margin: 0;
&:before {
.icon;
content: "\e013";
color: #999;
}
&:hover {
&:before {
.icon;
content: "\e013";
color: #999;
}
&:hover {
&:before {
color: @red;
}
color: @red;
}
}
}
.wc-order-edit-line-item-actions {
width: 2.5em;
text-align: right;
}
.wc-order-totals .wc-order-edit-line-item-actions {
width: 1.5em;
}
.wc-order-totals .edit-order-item {
margin: 0;
}
}
#woocommerce-order-downloads {

View File

@ -311,33 +311,6 @@ jQuery( function ( $ ) {
return false;
})
.on( 'click', '.save-action', function () {
var data = {
order_id: woocommerce_admin_meta_boxes.post_id,
items: $( 'table.woocommerce_order_items :input[name]' ).serialize(),
action: 'woocommerce_save_order_items',
security: woocommerce_admin_meta_boxes.order_item_nonce
};
addOrderItemsLoading();
$.ajax({
url: woocommerce_admin_meta_boxes.ajax_url,
data: data,
type: 'POST',
success: function( response ) {
$( '#woocommerce-order-items .inside' ).empty();
$( '#woocommerce-order-items .inside' ).append( response );
removeOrderItemsLoading();
}
});
return false;
})
.on( 'click', '.calculate-action', function () {
return false;
})
.on( 'click', '.cancel-action', function () {
$( this ).closest( 'div.wc-order-data-row' ).slideUp();
$( 'div.wc-order-bulk-actions' ).slideDown();
@ -397,7 +370,7 @@ jQuery( function ( $ ) {
}
})
.on( 'click', '.do_bulk_action', function() {
var action = $(this).closest('.bulk_actions').find('select').val();
var action = $(this).closest('.bulk-actions').find('select').val();
var selected_rows = $('#woocommerce-order-items').find('.check-column input:checked');
var item_ids = [];
@ -504,6 +477,74 @@ jQuery( function ( $ ) {
} );
}
return false;
})
.on( 'click', 'button.calculate-action', function () {
if ( window.confirm( woocommerce_admin_meta_boxes.calc_totals ) ) {
addOrderItemsLoading();
// Get row totals
var line_totals = 0;
var tax = 0;
var shipping = 0;
var order_discount = $( '#_order_discount' ).val() || '0';
order_discount = accounting.unformat( order_discount.replace( ',', '.' ) );
$( '#order_items_list tr.item, #order_items_list tr.shipping .wc_input_price' ).each( function () {
cost = $( this ).val() || '0';
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
shipping = shipping + parseFloat( cost );
});
$( '#tax_rows' ).find( 'input[type=number], .wc_input_price' ).each( function () {
cost = $( this ).val() || '0';
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
tax = tax + parseFloat( cost );
});
$( '#order_items_list tr.item, #order_items_list tr.fee' ).each( function () {
line_total = $( this ).find( 'input.line_total' ).val() || '0';
line_totals = line_totals + accounting.unformat( line_total.replace( ',', '.' ) );
});
// Tax
if ( 'yes' === woocommerce_admin_meta_boxes.round_at_subtotal ) {
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
}
// Set Total
$( '#_order_total' )
.val( accounting.formatNumber( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) )
.change();
$( 'button.save-action' ).click();
}
return false;
})
.on( 'click', 'button.save-action', function () {
var data = {
order_id: woocommerce_admin_meta_boxes.post_id,
items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize(),
action: 'woocommerce_save_order_items',
security: woocommerce_admin_meta_boxes.order_item_nonce
};
addOrderItemsLoading();
$.ajax({
url: woocommerce_admin_meta_boxes.ajax_url,
data: data,
type: 'POST',
success: function( response ) {
$( '#woocommerce-order-items .inside' ).empty();
$( '#woocommerce-order-items .inside' ).append( response );
removeOrderItemsLoading();
}
});
return false;
});
@ -671,51 +712,6 @@ jQuery( function ( $ ) {
} else {
$('.woocommerce_order_items_wrapper').unblock();
}
return false;
})
.on('click', 'button.calc_totals', function(){
// Block write panel
$('#woocommerce-order-totals').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
var answer = confirm(woocommerce_admin_meta_boxes.calc_totals);
if (answer) {
// Get row totals
var line_totals = 0;
var tax = 0;
var shipping = 0;
var order_discount = $('#_order_discount').val() || '0';
order_discount = accounting.unformat( order_discount.replace(',', '.') );
$('#shipping_rows').find('input[type=number], .wc_input_price').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
shipping = shipping + parseFloat( cost );
});
$('#tax_rows').find('input[type=number], .wc_input_price').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
tax = tax + parseFloat( cost );
});
$('#order_items_list tr.item, #order_items_list tr.fee').each(function(){
line_total = $(this).find('input.line_total').val() || '0';
line_totals = line_totals + accounting.unformat( line_total.replace(',', '.') );
});
// Tax
if ( woocommerce_admin_meta_boxes.round_at_subtotal == 'yes' )
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
// Set Total
$('#_order_total').val( accounting.formatNumber( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) ).change();
}
$('#woocommerce-order-totals').unblock();
return false;
});

File diff suppressed because one or more lines are too long

View File

@ -68,20 +68,6 @@ class WC_Meta_Box_Order_Totals {
<?php endif; ?>
<div class="totals_group">
<h4><label for="_order_discount"><?php _e( 'Order Discount', 'woocommerce' ); ?> <span class="tips" data-tip="<?php _e( 'This is the total discount applied after tax.', 'woocommerce' ); ?>">[?]</span></label></h4>
<input type="text" class="wc_input_price" id="_order_discount" name="_order_discount" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
if ( isset( $data['_order_discount'][0] ) )
echo esc_attr( wc_format_localized_price( $data['_order_discount'][0] ) );
?>" />
</div>
<div class="totals_group">
<h4><label for="_order_total"><?php _e( 'Order Total', 'woocommerce' ); ?></label></h4>
<input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
if ( isset( $data['_order_total'][0] ) )
echo esc_attr( wc_format_localized_price( $data['_order_total'][0] ) );
?>" />
</div>
<p class="buttons">
<?php if ( get_option( 'woocommerce_calc_taxes' ) == 'yes' ) : ?>
<button type="button" class="button calc_line_taxes"><?php _e( 'Calculate Tax', 'woocommerce' ); ?></button>
@ -210,8 +196,6 @@ class WC_Meta_Box_Order_Totals {
// Update totals
update_post_meta( $post_id, '_order_tax', wc_format_decimal( $total_tax ) );
update_post_meta( $post_id, '_order_shipping_tax', wc_format_decimal( $total_shipping_tax ) );
update_post_meta( $post_id, '_order_discount', wc_format_decimal( $_POST['_order_discount'] ) );
update_post_meta( $post_id, '_order_total', wc_format_decimal( $_POST['_order_total'] ) );
// Delete rows
if ( isset( $_POST['delete_order_item_id'] ) ) {
@ -220,9 +204,5 @@ class WC_Meta_Box_Order_Totals {
foreach ( $delete_ids as $id )
wc_delete_order_item( absint( $id ) );
}
delete_post_meta( $post_id, '_shipping_method' );
delete_post_meta( $post_id, '_shipping_method_title' );
add_post_meta( $post_id, '_order_currency', get_woocommerce_currency(), true );
}
}

View File

@ -3,7 +3,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<div class="woocommerce_order_items_wrapper">
<div class="woocommerce_order_items_wrapper wc-order-items-editable">
<table cellpadding="0" cellspacing="0" class="woocommerce_order_items">
<thead>
<tr>
@ -68,16 +68,18 @@ if ( ! defined( 'ABSPATH' ) ) {
</tbody>
</table>
</div>
<div class="wc-order-data-row wc-order-totals-items">
<div class="wc-order-data-row wc-order-totals-items wc-order-items-editable">
<table class="wc-order-totals">
<tr>
<td class="label"><?php _e( 'Shipping', 'woocommerce' ); ?>:</td>
<td class="total"><?php echo wc_price( $order->get_total_shipping() ); ?></td>
<td width="1%"></td>
</tr>
<?php if ( 'yes' == get_option( 'woocommerce_calc_taxes' ) ) : ?>
<tr>
<td class="label"><?php _e( 'Taxes', 'woocommerce' ); ?>:</td>
<td class="total"><?php echo wc_price( $order->get_total_tax() ); ?></td>
<td width="1%"></td>
</tr>
<?php endif; ?>
<tr>
@ -89,10 +91,12 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="clear"></div>
</div>
</td>
<td><div class="wc-order-edit-line-item-actions"><a class="edit-order-item" href="#"></a></div></td>
</tr>
<tr>
<td class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded() ); ?></td>
<td width="1%"></td>
</tr>
<tr>
<td class="label"><?php _e( 'Order Total', 'woocommerce' ); ?>:</td>
@ -103,12 +107,13 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="clear"></div>
</div>
</td>
<td><div class="wc-order-edit-line-item-actions"><a class="edit-order-item" href="#"></a></div></td>
</tr>
</table>
<div class="clear"></div>
</div>
<div class="wc-order-data-row wc-order-bulk-actions">
<p class="bulk_actions">
<p class="bulk-actions">
<select>
<option value=""><?php _e( 'Actions', 'woocommerce' ); ?></option>
<optgroup label="<?php _e( 'Edit', 'woocommerce' ); ?>">
@ -122,9 +127,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<button type="button" class="button do_bulk_action wc-reload" title="<?php _e( 'Apply', 'woocommerce' ); ?>"><span><?php _e( 'Apply', 'woocommerce' ); ?></span></button>
</p>
<p class="add_items">
<p class="add-items">
<button type="button" class="button add-line-item"><?php _e( 'Add line item(s)', 'woocommerce' ); ?></button>
<button type="button" class="button refund-items"><?php _e( 'Refund', 'woocommerce' ); ?></button>
<button type="button" class="button button-primary calculate-action"><?php _e( 'Calculate Total', 'woocommerce' ); ?></button>
</p>
</div>
<div class="wc-order-data-row wc-order-add-item" style="display:none;">

View File

@ -341,4 +341,15 @@ function wc_save_order_items( $order_id, $items ) {
// Update cart discount from item totals
update_post_meta( $order_id, '_cart_discount', $subtotal - $total );
// Update totals
update_post_meta( $order_id, '_order_discount', wc_format_decimal( $items['_order_discount'] ) );
update_post_meta( $order_id, '_order_total', wc_format_decimal( $items['_order_total'] ) );
// Remove old values
delete_post_meta( $order_id, '_shipping_method' );
delete_post_meta( $order_id, '_shipping_method_title' );
// Set the currency
add_post_meta( $order_id, '_order_currency', get_woocommerce_currency(), true );
}