@@ -9,11 +9,15 @@ import * as EmailValidator from "email-validator";
9
9
import { inject , observer } from "mobx-react/native" ;
10
10
import { currentLanguage } from "../../translations/CurrentLanguage" ;
11
11
12
+ import PaymentController from "./controller" ;
12
13
import PaymentScreen from "@screens/Payment" ;
14
+
13
15
import translation from "../../translations/translation" ;
14
16
import LocalizedStrings from "react-native-localization" ;
15
17
let strings = new LocalizedStrings ( translation ) ;
18
+
16
19
const moment = require ( "moment" ) ;
20
+
17
21
@inject (
18
22
"itemStore" ,
19
23
"customerStore" ,
@@ -30,9 +34,8 @@ const moment = require("moment");
30
34
export default class PaymentContainer extends React . Component {
31
35
constructor ( props ) {
32
36
super ( props ) ;
33
- this . state = {
34
- arrayObjects : [ ] ,
35
- } ;
37
+ this . controller = new PaymentController ( props . stateStore ) ;
38
+ this . state = { arrayObjects : [ ] } ;
36
39
}
37
40
38
41
componentWillMount ( ) {
@@ -120,7 +123,7 @@ export default class PaymentContainer extends React.Component {
120
123
}
121
124
}
122
125
123
- onValueChange ( text ) {
126
+ onValueChange = text => {
124
127
if ( text === "Del" ) {
125
128
const finalValue = this . props . stateStore . payment_value . slice ( 0 , - 1 ) ;
126
129
this . props . stateStore . setPaymentValue ( finalValue ) ;
@@ -137,7 +140,7 @@ export default class PaymentContainer extends React.Component {
137
140
}
138
141
}
139
142
}
140
- }
143
+ } ;
141
144
142
145
setOrderCompleted ( ) {
143
146
const {
@@ -984,21 +987,26 @@ export default class PaymentContainer extends React.Component {
984
987
this . props . navigation . goBack ( ) ;
985
988
}
986
989
987
- onPrinterChange ( value ) {
988
- this . props . stateStore . changeValue ( "itemSelected" , value , "Payment" ) ;
989
- BluetoothSerial . connect ( "DC:0D:30:0B:77:B1" )
990
- . then ( res => {
991
- this . props . stateStore . changeValue ( "connection" , true , "Payment" ) ;
992
- } )
993
- . catch ( ( ) => {
994
- // this.setState({ connection: false });
995
- this . props . stateStore . changeValue ( "connection" , false , "Payment" ) ;
996
- } ) ;
997
- }
998
-
999
- onPrinterPress ( ) {
990
+ navigation = ( ) => {
991
+ this . getBluetoothState ( true ) ;
992
+ this . onBack ( ) ;
993
+ } ;
994
+ // DEPRECATED
995
+ // onPrinterChange(value) {
996
+ // this.props.stateStore.changeValue("itemSelected", value, "Payment");
997
+ // BluetoothSerial.connect("DC:0D:30:0B:77:B1")
998
+ // .then(res => {
999
+ // this.props.stateStore.changeValue("connection", true, "Payment");
1000
+ // })
1001
+ // .catch(() => {
1002
+ // // this.setState({ connection: false });
1003
+ // this.props.stateStore.changeValue("connection", false, "Payment");
1004
+ // });
1005
+ // }
1006
+
1007
+ onPrinterPress = ( ) => {
1000
1008
this . props . navigation . navigate ( "Settings" ) ;
1001
- }
1009
+ } ;
1002
1010
1003
1011
onConnectDevice ( ) {
1004
1012
if ( this . props . printerStore . rows . length > 0 ) {
@@ -1075,7 +1083,8 @@ export default class PaymentContainer extends React.Component {
1075
1083
} ) ;
1076
1084
}
1077
1085
}
1078
- searchCustomer ( text ) {
1086
+
1087
+ searchCustomer = text => {
1079
1088
this . props . customerStore . search ( text ) . then ( result => {
1080
1089
for ( let i = 0 ; i < result . length ; i += 1 ) {
1081
1090
let existing = false ;
@@ -1089,8 +1098,9 @@ export default class PaymentContainer extends React.Component {
1089
1098
}
1090
1099
}
1091
1100
} ) ;
1092
- }
1093
- onSaveCustomer ( ) {
1101
+ } ;
1102
+
1103
+ onSaveCustomer = ( ) => {
1094
1104
if ( this . props . stateStore . payment_state [ 0 ] . customerName ) {
1095
1105
if (
1096
1106
EmailValidator . validate (
@@ -1115,14 +1125,15 @@ export default class PaymentContainer extends React.Component {
1115
1125
} else {
1116
1126
Alert . alert ( strings . InvalidEmail , strings . PleaseEnterValidEmail ) ;
1117
1127
}
1118
- }
1119
- onCancelAddCustomer ( ) {
1128
+ } ;
1129
+
1130
+ onCancelAddCustomer = ( ) => {
1120
1131
this . props . stateStore . changeValue ( "modalVisible" , false , "Payment" ) ;
1121
1132
this . props . stateStore . changeValue ( "customerName" , "" , "Payment" ) ;
1122
1133
this . props . stateStore . changeValue ( "customerEmail" , "" , "Payment" ) ;
1123
1134
this . props . stateStore . changeValue ( "customerPhoneNumber" , "" , "Payment" ) ;
1124
1135
this . props . stateStore . changeValue ( "customerNotes" , "" , "Payment" ) ;
1125
- }
1136
+ } ;
1126
1137
1127
1138
render ( ) {
1128
1139
strings . setLanguage ( currentLanguage ( ) . companyLanguage ) ;
@@ -1131,49 +1142,27 @@ export default class PaymentContainer extends React.Component {
1131
1142
values = { this . props . stateStore . payment_state [ 0 ] . toJSON ( ) }
1132
1143
paymentValue = { this . props . stateStore . payment_value }
1133
1144
amountDue = { this . props . stateStore . amount_due }
1134
- // value={this.props.stateStore.payment_value}
1135
- // modalVisible={this.props.stateStore.payment_state[0].modalVisible}
1136
1145
name = { this . props . stateStore . payment_state [ 0 ] . customerName }
1137
- connectDevice = { ( ) => this . onConnectDevice ( ) }
1138
- onPickerChange = { text =>
1139
- this . props . stateStore . changeValue ( "selected" , text , "Payment" )
1140
- }
1141
- onValueChange = { this . onValueChange . bind ( this ) }
1146
+ connectDevice = { this . onConnectDevice }
1147
+ onValueChange = { this . onValueChange }
1142
1148
defaultCustomer = {
1143
1149
this . props . receiptStore . defaultCustomer . name . toString ( )
1144
1150
? this . props . receiptStore . defaultCustomer . name . toString ( )
1145
1151
: "Default customer"
1146
1152
}
1147
1153
onPay = { this . onPay }
1148
- onPrinterChange = { value => this . onPrinterChange ( value ) }
1149
- searchCustomer = { text => this . searchCustomer ( text ) }
1154
+ searchCustomer = { this . searchCustomer }
1150
1155
searchedCustomers = { this . state . arrayObjects }
1151
- modalVisibleChange = { text =>
1152
- this . props . stateStore . changeValue ( "modalVisible" , text , "Payment" )
1153
- }
1154
- navigation = { ( ) => {
1155
- this . getBluetoothState ( true ) ;
1156
- this . onBack ( ) ;
1157
- } }
1158
- onPrinterPress = { ( ) => this . onPrinterPress ( ) }
1159
- onChangeaCustomerName = { text =>
1160
- this . props . stateStore . changeValue ( "customerName" , text , "Payment" )
1161
- }
1162
- onChangeCustomerEmail = { text =>
1163
- this . props . stateStore . changeValue ( "customerEmail" , text , "Payment" )
1164
- }
1165
- onChangeCustomerPhoneNumber = { text =>
1166
- this . props . stateStore . changeValue (
1167
- "customerPhoneNumber" ,
1168
- text ,
1169
- "Payment" ,
1170
- )
1171
- }
1172
- onChangeCustomerNotes = { text =>
1173
- this . props . stateStore . changeValue ( "customerNotes" , text , "Payment" )
1174
- }
1175
- onSaveCustomer = { ( ) => this . onSaveCustomer ( ) }
1176
- onCancelAddCustomer = { ( ) => this . onCancelAddCustomer ( ) }
1156
+ modalVisibleChange = { this . controller . modalVisibleChange }
1157
+ navigation = { this . navigation }
1158
+ onPrinterPress = { this . onPrinterPress }
1159
+ onChangePayment = { this . controller . onChangePayment }
1160
+ onChangeCustomerName = { this . controller . onChangeCustomerName }
1161
+ onChangeCustomerEmail = { this . controller . onChangeCustomerEmail }
1162
+ onChangeCustomerPhoneNumber = { this . onChangeCustomerPhoneNumber }
1163
+ onChangeCustomerNotes = { this . controller . onChangeCustomerNotes }
1164
+ onSaveCustomer = { this . onSaveCustomer }
1165
+ onCancelAddCustomer = { this . onCancelAddCustomer }
1177
1166
currency = {
1178
1167
this . props . printerStore . companySettings [ 0 ] . countryCode
1179
1168
? this . props . printerStore . companySettings [ 0 ] . countryCode
0 commit comments