Skip to content
Permalink
Browse files

New: add pos_cash info to receipt data

  • Loading branch information...
kilbot committed Aug 22, 2015
1 parent 37f604c commit e7e443ba07aff02f3927f2c08128e062b81fe5c1
@@ -99,7 +99,7 @@ module.exports = FormView.extend({
calcChange: function(tendered){
var change = tendered - this.order_total;
var msg = polyglot.t('titles.change') + ': ' + Utils.formatMoney(change);
this.model.set({ message: msg });
this.model.set({ message: msg, 'pos-cash-change': change });
},

updateStatusMessage: function(){
@@ -532,13 +532,12 @@ public function payment_complete( $order_id ) {
public function order_response( $order_data, $order, $fields, $server ) {
// add cashier data
$cashier_data = isset( $order_data['cashier'] ) ? $order_data['cashier'] : array();
$order_data['cashier'] = $this->add_cashier_data( $order->id, $cashier_data );
$cashier_details = isset( $order_data['cashier'] ) ? $order_data['cashier'] : array();
$order_data['cashier'] = $this->add_cashier_details( $order, $cashier_details );
// add pos payment info
$order_data['payment_details']['result'] = get_post_meta( $order->id, '_pos_payment_result', true );
$order_data['payment_details']['message'] = get_post_meta( $order->id, '_pos_payment_message', true );
$order_data['payment_details']['redirect'] = get_post_meta( $order->id, '_pos_payment_redirect', true );
$payment_details = isset( $order_data['payment_details'] ) ? $order_data['payment_details'] : array();
$order_data['payment_details'] = $this->add_payment_details( $order, $payment_details );
// addresses
// $order_data['billing_address'] = $this->filter_address($order_data['billing_address'], $order);
@@ -574,22 +573,37 @@ public function order_response( $order_data, $order, $fields, $server ) {
}
/**
* @param $order_id
* @param $order
* @param array $cashier
* @return array
*/
private function add_cashier_data( $order_id, array $cashier = array() ){
$cashier['id'] = get_post_meta( $order_id, '_pos_user', true);
$first_name = get_post_meta( $order_id, '_pos_user_first_name', true);
$last_name = get_post_meta( $order_id, '_pos_user_last_name', true);
private function add_cashier_details( $order, array $cashier = array() ){
$cashier['id'] = get_post_meta( $order->id, '_pos_user', true);
$first_name = get_post_meta( $order->id, '_pos_user_first_name', true);
$last_name = get_post_meta( $order->id, '_pos_user_last_name', true);
if( !$first_name && !$last_name ) {
$user_info = get_userdata( $cashier['id'] );
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
}
$cashier['first_name'] = $first_name;
$cashier['last_name'] = $last_name;
return $cashier;
return apply_filters( 'woocommerce_pos_order_response_cashier', $cashier, $order );
}
/**
* @param $order
* @param array $payment
* @return array
*/
private function add_payment_details( $order, array $payment = array() ){
$payment['result'] = get_post_meta( $order->id, '_pos_payment_result', true );
$payment['message'] = get_post_meta( $order->id, '_pos_payment_message', true );
$payment['redirect'] = get_post_meta( $order->id, '_pos_payment_redirect', true );
if( isset( $payment['method_id'] ) && $payment['method_id'] == 'pos_cash' ){
$payment = WC_POS_Gateways_Cash::payment_details( $payment, $order );
}
return apply_filters( 'woocommerce_pos_order_response_payment_details', $payment, $order );
}
/**
@@ -113,7 +113,7 @@ public function calculate_cashback( $order_id ) {
// construct message
if( $cashback ) {
$message = '<strong>'. __('Cashback', 'woocommerce-pos') .':</strong> ';
$message = __('Cashback', 'woocommerce-pos') . ': ';
$message .= wc_price($cashback);
}
@@ -65,21 +65,11 @@ public function process_payment( $order_id ) {
// get order object
$order = new WC_Order( $order_id );
$tendered = isset( $_REQUEST['pos-cash-tendered'] ) ? wc_format_decimal( $_REQUEST['pos-cash-tendered'] ) : 0 ;
$tendered = abs((float) $tendered);
$total = isset( $_REQUEST['total'] ) ? $_REQUEST['total'] : 0 ;
$total = abs((float) $total);
if( $tendered !== 0 ) {
// calculate change
$change = $tendered - $total;
// add order meta
update_post_meta( $order_id, '_pos_cash_amount_tendered', $tendered );
update_post_meta( $order_id, '_pos_cash_change', $change );
}
// update pos_cash data
$tendered = isset( $_POST['pos-cash-tendered'] ) ? wc_format_decimal( $_POST['pos-cash-tendered'] ) : 0 ;
$change = isset( $_POST['pos-cash-change'] ) ? wc_format_decimal( $_POST['pos-cash-change'] ) : 0 ;
update_post_meta( $order_id, '_pos_cash_amount_tendered', $tendered );
update_post_meta( $order_id, '_pos_cash_change', $change );
// payment complete
$order->payment_complete();
@@ -97,13 +87,21 @@ public function calculate_change( $order_id ) {
// construct message
if( $tendered && $change ) {
$message = '<strong>'. __('Amount Tendered', 'woocommerce-pos') .':</strong> ';
$message = __('Amount Tendered', 'woocommerce-pos') .': ';
$message .= wc_price($tendered) .'<br>';
$message .= '<strong>'. _x('Change', 'Money returned from cash sale', 'woocommerce-pos') .':</strong> ';
$message .= _x('Change', 'Money returned from cash sale', 'woocommerce-pos') .': ';
$message .= wc_price($change);
}
echo $message;
}
static public function payment_details( $payment_details, $order ) {
$payment_details['method_pos_cash'] = array(
'tendered' => get_post_meta( $order->id, '_pos_cash_amount_tendered', true ),
'change' => get_post_meta( $order->id, '_pos_cash_change', true )
);
return $payment_details;
}
}
@@ -48,7 +48,7 @@
width: 100%;
}
table tr {
border-bottom: 1px solid #bbb;
border-bottom: 1px solid #dddddd;
}
table th, table td {
padding: 6px 12px;
@@ -97,6 +97,12 @@
tfoot th {
width: 70%;
}
tfoot tr.order-total {
font-weight: bold;
}
tfoot tr.pos_cash-tendered th, tfoot tr.pos_cash-tendered td {
border-top: 1px solid #000;
}
</style>
</head>

@@ -236,6 +242,16 @@
<th colspan="2"><?php /* translators: woocommerce */ _e( 'Order Total', 'woocommerce' ); ?>:</th>
<td colspan="1">{{{money total}}}</td>
</tr>
{{#if payment_details.method_pos_cash}}
<tr class="pos_cash-tendered">
<th colspan="2"><?php _e( 'Amount Tendered', 'woocommerce-pos' ); ?>:</th>
<td colspan="1">{{{money payment_details.method_pos_cash.tendered}}}</td>
</tr>
<tr class="pos_cash-change">
<th colspan="2"><?php _ex('Change', 'Money returned from cash sale', 'woocommerce-pos'); ?>:</th>
<td colspan="1">{{{money payment_details.method_pos_cash.change}}}</td>
</tr>
{{/if}}
</tfoot>
</table>
<div class="order-notes">{{note}}</div>
@@ -80,7 +80,9 @@ Bugs can be reported on the [WooCommerce POS GitHub repository](https://github.c
= 0.4.2 =
* New: local storage will now clear on version change - commit [85ec411](https://github.com/kilbot/WooCommerce-POS/commit/85ec411a58600988b811272be6d151cb11161f4f)
* New: option to automatically print receipt after checkout - commit [16fba05](https://github.com/kilbot/WooCommerce-POS/commit/16fba054593e118be6c567ce4d87f8d0b91acaa5)
* New: add cashier to receipt data - commit []()
* New: add cashier to receipt data - commit [c4caa8d](https://github.com/kilbot/WooCommerce-POS/commit/c4caa8df78d9f255445f370854fbb3e466b46b4e)
* New: add pos_cash info to receipt data - commit []()
* New: WooPOS icon to denote POS orders in WP Admin
* Fix: variation display and select issues - commit [91c7ec1](https://github.com/kilbot/WooCommerce-POS/commit/91c7ec13e737f820d84feb7890d7b6d027a79792), [b3d6543](https://github.com/kilbot/WooCommerce-POS/commit/b3d6543b86140df62ff90f3a7b7e734d73ae59ab)
* Fix: variation barcode search for products in queue - commit [3fda531](https://github.com/kilbot/WooCommerce-POS/commit/3fda5317ef580f6b6d70e24ba235d2b7e69c5ee4)
* Fix: variation stock adjustment after sale - commit [26978fd](https://github.com/kilbot/WooCommerce-POS/commit/26978fd0e74cfb9cf28ef2bb4bc5222820a77d38)
@@ -1,5 +1,7 @@
describe('entities/service.js', function () {

var Marionette = require('backbone.marionette');

beforeEach(function () {

var Module = proxyquire('entities/service', {
@@ -82,7 +84,7 @@ describe('entities/service.js', function () {
//});

it('should return an app option using { type: "option" }', function(){
this.module.app = new Backbone.Marionette.Application({ foo: 'bar' });
this.module.app = new Marionette.Application({ foo: 'bar' });
var foo = this.module.channel.request('get', {
type: 'option',
name: 'foo'
@@ -91,7 +93,7 @@ describe('entities/service.js', function () {
});

it('should return a settings Model using { type: "settings" }', function(){
this.module.app = new Backbone.Marionette.Application({ foo: { user: 'setting' } });
this.module.app = new Marionette.Application({ foo: { user: 'setting' } });
var foo = this.module.channel.request('get', {
type: 'settings',
name: 'foo'
@@ -1,6 +1,7 @@
describe('lib/utilities/global.js', function () {

var POS = require('lib/utilities/global');
var Marionette = require('backbone.marionette');

beforeEach(function () {
this.POS = _.clone(POS);
@@ -33,11 +34,11 @@ describe('lib/utilities/global.js', function () {
});

it('should create a global Marionette App with custom properties', function () {
var app = new Backbone.Marionette.Application();
var app = new Marionette.Application();
this.POS.attach('Module.SubModule', { foo: 'bar' });
var POS = this.POS.create(app);
POS.module('Module');
expect(POS).to.be.an.instanceof(Backbone.Marionette.Application);
expect(POS).to.be.an.instanceof(Marionette.Application);
expect(POS).to.have.deep.property('Module.SubModule.foo', 'bar');
});

0 comments on commit e7e443b

Please sign in to comment.
You can’t perform that action at this time.