NewReceiptDetailActivity.java
9.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.huaheng.mobilewms.refactor;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.huaheng.mobilewms.R;
import com.huaheng.mobilewms.WMSApplication;
import com.huaheng.mobilewms.activity.model.CommonActivity;
import com.huaheng.mobilewms.bean.Receipt;
import com.huaheng.mobilewms.bean.ReceiptBill;
import com.huaheng.mobilewms.bean.ReceiptDetail;
import com.huaheng.mobilewms.bean.ReceiptHeader;
import com.huaheng.mobilewms.https.HttpInterface;
import com.huaheng.mobilewms.https.Subscribers.ProgressSubscriber;
import com.huaheng.mobilewms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.mobilewms.util.SpeechUtil;
import com.huaheng.mobilewms.util.WMSUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
public class NewReceiptDetailActivity extends CommonActivity implements View.OnClickListener {
private String receiptCode, label;
public Context mContext;
ListView receiptListView;
ImageView backImage;
LinearLayout contentLayout;
TextView receiptNoView, containerCode_label;
EditText containerEdit;
Button sortBt, ensureBtn;
ReceiptHeader receiptHeader;
List<ReceiptDetail> receiptDetailList;
ReceiptDetailAdapter adapter;
//收货容器
HashMap<String, List<ReceiptBill>> containerMap = new HashMap<>();
//当前容器编码
String currentContainerCode;
Bundle bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_receipt_detail);
bundle = getIntent().getExtras();
receiptCode = bundle.getString("receiptCode");
label = bundle.getString("label");
mContext = this;
findReceipt(receiptCode);
initView();
switchButton();
}
private void initView() {
backImage = findViewById(R.id.backImage);
backImage.setOnClickListener(this);
contentLayout = findViewById(R.id.contentLayout);
receiptListView = findViewById(R.id.receiptListView);
receiptNoView = findViewById(R.id.receipt_no);
receiptNoView.setText(receiptCode);
containerEdit = findViewById(R.id.containerEdit);
sortBt = findViewById(R.id.sortBt);
containerCode_label = findViewById(R.id.containerCode_label);
ensureBtn = findViewById(R.id.ensureBtn);
sortBt.setOnClickListener(this);
ensureBtn.setOnClickListener(this);
containerCode_label.setOnClickListener(this);
containerEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
String text = textView.getText().toString();
text = text.trim().toUpperCase();
textView.setText(text);
if (WMSUtils.isNotEmpty(text)) {
isContainer(text);
}
return false;
}
});
}
private void initList() {
adapter = new ReceiptDetailAdapter(mContext, receiptDetailList);
receiptListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
sortListByQtyZero();
}
public void sortListByQtyZero(){
receiptDetailList.sort(new Comparator<ReceiptDetail>() {
@Override
public int compare(ReceiptDetail o1, ReceiptDetail o2) {
return o2.tobeCollectQty() - o1.tobeCollectQty();
}
});
adapter.updateList(receiptDetailList);
adapter.notifyDataSetChanged();
}
/**
* 按用户是否选中做排序
*/
public void sortListBySelection(){
receiptDetailList.sort(new Comparator<ReceiptDetail>() {
@Override
public int compare(ReceiptDetail o1, ReceiptDetail o2) {
if(o1.isSelected() && o2.isSelected())
return 0;
if(o1.isSelected() && !o2.isSelected())
return -1;
if(!o1.isSelected() && o2.isSelected())
return 1;
// return o2.getQtySelected() - o1.getQtySelected();
return 0;
}
});
adapter.updateList(receiptDetailList);
adapter.notifyDataSetChanged();
}
private void findReceipt(String receiptCode) {
HttpInterface.getInsstance().findReceipt(new ProgressSubscriber<Receipt>(mContext, receiptListener), receiptCode);
}
SubscriberOnNextListener receiptListener = new SubscriberOnNextListener<Receipt>() {
@Override
public void onNext(Receipt receipt) {
if (receipt != null) {
receiptHeader = receipt.getReceiptHeader();
receiptDetailList = receipt.getReceiptDetails();
initList();
} else {
WMSUtils.showShort(getString(R.string.toast_error));
}
}
@Override
public void onError(String str) {
}
};
public void isContainer(String containerCode) {
HttpInterface.getInsstance().isContainer(new ProgressSubscriber<String>(this, isContainerListener), containerCode);
}
SubscriberOnNextListener isContainerListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
updateContainerCode(str);
}
@Override
public void onError(String str) {
}
};
private void listReceipt(List<ReceiptBill> billList) {
HttpInterface.getInsstance().listReceipt(new ProgressSubscriber <String>(this, quickReceiptListener), billList);
}
SubscriberOnNextListener quickReceiptListener = new SubscriberOnNextListener <String>() {
@Override
public void onNext(String result) {
SpeechUtil.getInstance(mContext).speech(mContext.getString(R.string.receipt_success));
if(isAllReceiptDone()) {
finish();
}else{
finish();
Intent intent = new Intent();
intent.setClass(mContext, NewReceiptDetailActivity.class);
intent.putExtras(bundle);// 发送数据
WMSApplication.getContext().startActivity(intent);
}
}
@Override
public void onError(String str) {
}
};
/**
* 根据用户的选择生成需要提交到后台的ReceiptBill
**/
private List<ReceiptBill> getReceiptSelected() {
List<ReceiptBill> billList = new ArrayList<>();
for (ReceiptDetail detail : receiptDetailList) {
if (detail.getQtySelected() > 0) {
ReceiptBill bill = new ReceiptBill();
bill.setBatch(detail.getBatch());
BigDecimal qty = new BigDecimal(detail.getQtySelected());
bill.setQty(qty);
bill.setMaterialCode(detail.getMaterialName());
bill.setMaterialCode(detail.getMaterialCode());
bill.setProject(detail.getProjectNo());
bill.setReceiptDetailId(String.valueOf(detail.getId()));
bill.setReceiptContainerCode(currentContainerCode);
billList.add(bill);
}
}
return billList;
}
/**检查是否还有未收的物料**/
private boolean isAllReceiptDone(){
int tobeCollectSum = 0;
int userSelectQtySum = 0;
for (ReceiptDetail detail : receiptDetailList) {
tobeCollectSum += detail.tobeCollectQty();
if (detail.getQtySelected() > 0) {
userSelectQtySum += detail.getQtySelected();
}
}
if(userSelectQtySum < tobeCollectSum){
//未收完
return false;
}else{
//已收完
return true;
}
}
/**
* 提交收货
**/
private void save() {
if (TextUtils.isEmpty(currentContainerCode)) {
WMSUtils.showShort("还没有选择容器");
return;
}
List<ReceiptBill> billList = getReceiptSelected();
if (billList.size() == 0) {
WMSUtils.showShort("还没有选择收货的物料");
return;
}
listReceipt(billList);
}
/**
* 检查并且切换是否可以提交
*/
public void switchButton() {
boolean enable = !TextUtils.isEmpty(currentContainerCode) && getReceiptSelected().size()>0;
if (enable) {
ensureBtn.setBackgroundResource(R.drawable.blue_button_bg);
ensureBtn.setClickable(true);
ensureBtn.setClickable(true);
} else {
ensureBtn.setBackgroundResource(R.drawable.gray_button_bg);
ensureBtn.setClickable(false);
ensureBtn.setClickable(false);
}
}
/**更新所选容器**/
private void updateContainerCode(String code){
currentContainerCode = code;
containerEdit.setText(code);
if(TextUtils.isEmpty(code)) {
containerEdit.requestFocus();
}
switchButton();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sortBt:
sortListBySelection();
break;
case R.id.containerCode_label:
updateContainerCode("");
break;
case R.id.backImage:
finish();
break;
case R.id.ensureBtn:
save();
break;
default:
break;
}
}
}