247
247
<td class =" label" >
248
248
{{ __( 'Subtotal', 'wepos' ) }}
249
249
<span class =" name" v-if =" settings.woo_tax.wc_tax_display_cart == 'incl' && $store.getters['Cart/getTotalLineTax'] > 0" >
250
- {{ __( 'Includes Tax', 'wepos' ) }} {{ formatPrice( $store.getters['Cart/getTotalLineTax'] ) }}
250
+ {{ __( 'Including Tax', 'wepos' ) }}
251
251
</span >
252
252
</td >
253
253
<td class =" price" >{{ formatPrice( $store.getters['Cart/getSubtotal'] ) }}</td >
254
254
<td class =" action" ></td >
255
255
</tr >
256
+
257
+ <template v-if =" cartdata .coupon_lines .length > 0 " >
258
+ <tr class =" cart-meta-data" v-for =" (fee,key) in cartdata.coupon_lines" >
259
+ <template v-if =" fee .type == ' discount' " >
260
+ <td class =" label" >{{ __( 'Discount', 'wepos' ) }} <span class =" name" >{{ getDiscountAmount( fee ) }}</span ></td >
261
+ <td class =" price" >&minus ; {{ formatPrice( Math.abs( fee.total ) ) }}</td >
262
+ <td class =" action" ><span class =" flaticon-cancel-music" @click =" removeCouponLine(key)" ></span ></td >
263
+ </template >
264
+ <template v-else >
265
+ <template v-if =" cartdata .coupon_lines [key ].isEdit " >
266
+ <td class =" label" colspan =" 2" >
267
+ <input type =" text" class =" fee-name" v-model =" feeData.name" :placeholder =" __( 'Fee Name', 'wepos' )" ref =" fee_name" >
268
+ <input type =" number" class =" fee-amount" min =" 0" step =" any" v-model =" feeData.value" :placeholder =" __( 'Total', 'wepos' )" ref =" fee_total" >
269
+ <template v-if =" settings .wepos_general .enable_fee_tax == ' yes' " >
270
+ <label for =" fee-tax-status" ><input type =" checkbox" id =" fee-tax-status" class =" fee-tax-status" v-model =" feeData.tax_status" :true-value =" 'taxable'" :false-value =" 'none'" > {{ __( 'Taxable', 'wepos' ) }}</label >
271
+ <select class =" fee-tax-class" v-model =" feeData.tax_class" v-if =" feeData.tax_status=='taxable'" >
272
+ <option v-for =" feeTax in availableTax" :value =" feeTax.class == 'standard' ? '' : feeTax.class" >{{ unSanitizeString( feeTax.class ) }} - {{ feeTax.percentage_rate }}</option >
273
+ </select >
274
+ </template >
275
+ <button :disabled =" feeData.name == ''" @click.prevent =" saveFee(key)" >{{ __( 'Apply', 'wepos' ) }}</button >
276
+ <button class =" cancel" @click.prevent =" cancelEditFee(key)" >{{ __( 'Cancel', 'wepos' ) }}</button >
277
+ </td >
278
+ <td class =" action" ><span class =" flaticon-cancel-music" @click =" removeCouponLine(key)" ></span ></td >
279
+ </template >
280
+ <template v-else >
281
+ <td class =" label" @dblclick.prevent =" editFeeData(key)" >{{ __( 'Fee', 'wepos' ) }} <span class =" name" >{{ fee.name }} {{ getDiscountAmount( fee ) }}</span ></td >
282
+ <td class =" price" >{{ formatPrice( Math.abs( fee.total ) ) }}</td >
283
+ <td class =" action" ><span class =" flaticon-cancel-music" @click =" removeCouponLine(key)" ></span ></td >
284
+ </template >
285
+ </template >
286
+ </tr >
287
+ </template >
288
+
256
289
<template v-if =" cartdata .fee_lines .length > 0 " >
257
290
<tr class =" cart-meta-data" v-for =" (fee,key) in cartdata.fee_lines" >
258
291
<template v-if =" fee .type == ' discount' " >
285
318
</tr >
286
319
</template >
287
320
<tr class =" tax" v-if =" $store.getters['Cart/getTotalTax']" >
288
- <td class =" label" >{{ __( 'Tax', 'wepos' ) }}</td >
321
+ <td class =" label" >{{ settings.woo_tax.wc_tax_display_cart === 'incl' ? __( 'Fee Tax', 'wepos' ) : __( 'Tax', 'wepos' ) }}</td >
289
322
<td class =" price" >{{ formatPrice( $store.getters['Cart/getTotalTax'] ) }}</td >
290
323
<td class =" action" ></td >
291
324
</tr >
443
476
<span class =" wepos-left" >
444
477
{{ __( 'Subtotal', 'wepos' ) }}
445
478
<span class =" metadata" v-if =" settings.woo_tax.wc_tax_display_cart == 'incl'" >
446
- {{ __( 'Includes Tax', 'wepos' ) }} {{ formatPrice( $store.getters['Cart/getTotalLineTax'] ) }}
479
+ {{ __( 'Including Tax', 'wepos' ) }}
447
480
</span >
448
481
</span >
449
482
<span class =" wepos-right" >{{ formatPrice( $store.getters['Cart/getSubtotal'] ) }}</span >
450
483
</li >
484
+
485
+ <template v-if =" cartdata .coupon_lines .length > 0 " >
486
+ <li class =" wepos-clearfix" v-for =" (fee,key) in cartdata.coupon_lines" >
487
+ <template v-if =" fee .type == ' discount' " >
488
+ <span class =" wepos-left" >{{ __( 'Discount', 'wepos' ) }} <span class =" metadata" >{{ fee.name }} {{ getDiscountAmount( fee ) }}</span ></span >
489
+ <span class =" wepos-right" >-{{ formatPrice( Math.abs( fee.total ) ) }}</span >
490
+ </template >
491
+ <template v-else >
492
+ <span class =" wepos-left" >{{ __( 'Fee', 'wepos' ) }} <span class =" metadata" >{{ fee.name }} {{ getDiscountAmount( fee ) }}</span ></span >
493
+ <span class =" wepos-right" >{{ formatPrice( fee.total ) }}</span >
494
+ </template >
495
+ </li >
496
+ </template >
497
+
451
498
<template v-if =" cartdata .fee_lines .length > 0 " >
452
499
<li class =" wepos-clearfix" v-for =" (fee,key) in cartdata.fee_lines" >
453
500
<template v-if =" fee .type == ' discount' " >
@@ -619,6 +666,7 @@ export default {
619
666
availableGatewayContent: wepos .hooks .applyFilters ( ' wepos_avaialable_gateway_content' , [] ),
620
667
afterMainContents: wepos .hooks .applyFilters ( ' wepos_after_main_content' , [] ),
621
668
beforCartPanels: wepos .hooks .applyFilters ( ' wepos_before_cart_panel' , [] ),
669
+ couponData: {},
622
670
}
623
671
},
624
672
computed: {
@@ -792,6 +840,7 @@ export default {
792
840
shipping: this .orderdata .shipping ,
793
841
line_items: this .cartdata .line_items ,
794
842
fee_lines: this .cartdata .fee_lines ,
843
+ coupon_lines: this .cartdata .coupon_lines ,
795
844
customer_id: this .orderdata .customer_id ,
796
845
customer_note: this .orderdata .customer_note ,
797
846
payment_method: this .orderdata .payment_method ,
@@ -817,6 +866,19 @@ export default {
817
866
818
867
wepos .api .post ( wepos .rest .root + wepos .rest .wcversion + ' /orders' , orderdata )
819
868
.done ( response => {
869
+ const orderResult = response;
870
+ const totalTaxes = {};
871
+
872
+ // Looping through line items and get total tax for each items.
873
+ orderResult .line_items .forEach ( item => {
874
+ totalTaxes[item .product_id ] = item .total_tax
875
+ } );
876
+
877
+ // Preserve total tax amount for each of the line items to the cart.
878
+ this .cartdata .line_items .forEach ( item => {
879
+ item .total_tax = totalTaxes[ item .product_id ];
880
+ } );
881
+
820
882
wepos .api .post ( wepos .rest .root + wepos .rest .posversion + ' /payment/process' , response )
821
883
.done ( data => {
822
884
if ( data .result == ' success' ) {
@@ -830,14 +892,15 @@ export default {
830
892
this .printdata = wepos .hooks .applyFilters ( ' wepos_after_payment_print_data' , {
831
893
line_items: this .cartdata .line_items ,
832
894
fee_lines: this .cartdata .fee_lines ,
895
+ coupon_lines: this .cartdata .coupon_lines ,
833
896
subtotal: this .$store .getters [' Cart/getSubtotal' ],
834
897
taxtotal: this .$store .getters [' Cart/getTotalTax' ],
835
898
ordertotal: this .$store .getters [' Cart/getTotal' ],
836
899
gateway: {
837
900
id: response .payment_method ,
838
901
title: response .payment_method_title
839
902
},
840
- order_id: response .id ,
903
+ order_id: response .number ,
841
904
order_date: response .date_created ,
842
905
cashamount: this .cashAmount .toString (),
843
906
changeamount: this .changeAmount .toString ()
@@ -881,7 +944,49 @@ export default {
881
944
return ( product .images .length > 0 ) ? product .images [0 ].name : product .name ;
882
945
},
883
946
setDiscount ( value , type ) {
884
- this .$store .dispatch ( ' Cart/addDiscountAction' , { title: this .__ ( ' Discount' , ' wepos' ), value: value, type: type } );
947
+ this .createCoupon ( value, type, this .dispatchCoupon );
948
+ },
949
+ createCoupon ( amount , discount_type , callback ) {
950
+ let self = this ;
951
+ let id = Date .now ();
952
+ let code = discount_type + id + amount;
953
+
954
+ self .couponData = {};
955
+
956
+ const discountdata = {
957
+ code: code,
958
+ amount: amount,
959
+ usage_limit: 1 ,
960
+ meta_data : [
961
+ {
962
+ key: ' wepos_cart_discount' ,
963
+ value: ' yes' ,
964
+ },
965
+ ],
966
+ }
967
+
968
+ if ( ' percent' === discount_type ) {
969
+ discountdata .discount_type = discount_type;
970
+ }
971
+
972
+ wepos .api .post ( wepos .rest .root + wepos .rest .posversion + ' /coupons' , discountdata )
973
+ .done ( data => {
974
+ self .couponData = data;
975
+
976
+ callback ( data, discount_type );
977
+ } ).fail ( data => {
978
+ alert ( data .responseJSON .message );
979
+ } );
980
+ },
981
+ dispatchCoupon ( couponData , type ) {
982
+ this .$store .dispatch (
983
+ ' Cart/addDiscountAction' ,
984
+ {
985
+ title: this .__ ( ' Discount' , ' wepos' ),
986
+ value: couponData,
987
+ type
988
+ }
989
+ );
885
990
},
886
991
saveFee ( key ) {
887
992
this .$store .dispatch ( ' Cart/saveFeeValueAction' , { key: key, feeData: this .feeData } );
@@ -901,6 +1006,9 @@ export default {
901
1006
setFee ( value , type ) {
902
1007
this .$store .dispatch ( ' Cart/addFeeAction' , { title: this .__ ( ' Fee' , ' wepos' ), value: value, type: type } );
903
1008
},
1009
+ removeCouponLine ( key ) {
1010
+ this .$store .dispatch ( ' Cart/removeCouponLineItemsAction' , key );
1011
+ },
904
1012
removeFeeLine ( key ) {
905
1013
this .$store .dispatch ( ' Cart/removeFeeLineItemsAction' , key );
906
1014
},
0 commit comments