package com.novelbook.android.Fragments; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.novelbook.android.R; import com.novelbook.android.bean.StockInDetailPackBarcode; import com.novelbook.android.netsubscribe.BookSubscribe; import com.novelbook.android.netutils.OnSuccessAndFaultListener; import com.novelbook.android.netutils.OnSuccessAndFaultSub; import com.novelbook.android.utils.Enums; import com.novelbook.android.utils.WmsUtil; import org.json.JSONObject; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import butterknife.BindView; import butterknife.OnClick; import butterknife.OnEditorAction; public class StockInSeedsOut2Fragment extends BasicFragment { public static final String TAG = StockInSeedsOut2Fragment.class.getSimpleName(); @BindView(R.id.editPreinNo) EditText edPreinNo; @BindView(R.id.ed_seedsCnt) EditText edSeedsCnt; @BindView(R.id.edFlowNo) EditText edFlowNo; @BindView(R.id.goodsName) TextView tvGoodsName; @BindView(R.id.barcode) TextView tvBarcode; @BindView(R.id.tvunit) TextView tvUnit; @BindView(R.id.validCnt) TextView tvValidCnt; @BindView(R.id.edProductDate) EditText edProductDate; @BindView(R.id.btnLastPage) TextView btnLastPage; @BindView(R.id.btnNextPage) TextView btnNextPage; @BindView(R.id.tvPages) TextView tvPages; @BindView(R.id.tvCustomer) TextView tvCustomer; @BindView(R.id.tv_seedsCnt) TextView tvSeedsCnt; @BindView(R.id.tv_orderCnt) TextView tvOrderCnt; @BindView(R.id.bigcount) TextView tvBigCount; @BindView(R.id.tvSeedsCnt) TextView tvSeedsTotalCnt; @BindView((R.id.rdByCust)) RadioButton rdByCust; @BindView((R.id.btnConfirm)) Button btnConfirm; @BindView((R.id.btnQuery)) Button btnQuery; @BindView(R.id.editBarcode) EditText edBarcode; @BindView(R.id.tvUnit2) TextView tvUnit2; @BindView(R.id.chkOnce) CheckBox chkOnce; @BindView(R.id.chkPrintFlow) CheckBox chkPrint; @Override protected int getLayoutRes() { return R.layout.fragment_stock_in_seeds_out2; } private List mDatas = new ArrayList(); private int currentPage; Enums.enumValidInResult validResult;; String preNo="",barcode=""; public void setPreInNo(String preInNo){ this.preNo=preInNo; } public void setBarcode(String barcode){ this.barcode=barcode; } @Override protected void initDebugData() { // edPreinNo.setText("PE23061500030"); edSeedsCnt.setText("1"); } @OnEditorAction({R.id.editPreinNo,R.id.editBarcode}) boolean onEditorAction(KeyEvent key) { validResult=null; if (!WmsUtil.isKeyEnterDown(key)) { return true; } preNo =edPreinNo.getText().toString().trim().replaceAll("\\r|\\n",""); barcode =edBarcode.getText().toString().trim().replaceAll("\\r|\\n",""); currentPage=0; if(!TextUtils.isEmpty(barcode) &&mDatas.size()>0){ List tmp = new ArrayList(); for (StockInDetailPackBarcode s: mDatas ) { if(s.getCustomerId().equalsIgnoreCase(barcode)){ tmp.add(s); } } if(tmp.size()>0){ mDatas=tmp ; fillData(); return true; } } doGetValidInDetail(); // edBarcode.selectAll();; // edBarcode.requestFocus(); return false; } private void doGetValidInDetail() { //String preNo = edPreinNo.getText().toString(); // String barcode = edBarcode.getText().toString(); if(preNo.length()==0){ setInfo("请输入到货单"); edPreinNo.selectAll();; edPreinNo.requestFocus(); return; } preNo =edPreinNo.getText().toString().trim().replaceAll("\\r|\\n",""); barcode =edBarcode.getText().toString().trim().replaceAll("\\r|\\n",""); setInfo(""); String orderBy =rdByCust.isChecked()?"0":"1"; BookSubscribe.getZhiTongOrderByCust(preNo ,barcode,orderBy, new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { @Override public void onSuccess(String result) { try { Gson gson = new Gson(); mDatas = new ArrayList(); Type type = new TypeToken>(){}.getType(); mDatas =(List ) gson.fromJson(result,type); Log.d(TAG,"get stock items succeed, size is " + mDatas.size()); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "onSuccess: 解析失败", e); } Log.d(TAG, "progress: progress to hide"); handler.sendEmptyMessage(1); } @Override public void onSuccess(JSONObject jsonObject) { } @Override public void onFault(String errorMsg) { //tvIp.setText("failure"); //失败 Log.e(TAG, "error on get firstpage: " + errorMsg); failureMsg =errorMsg; handler.sendEmptyMessage(2); } }, this.getActivity(),true)); } @Override protected void initData() { clearDetail(); chkPrint.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chkPrint =(CheckBox) v; if(chkPrint.isChecked()){ connectBlues(); edFlowNo.setEnabled(false); edFlowNo.setText(getRandomFlowNo()); }else{ edFlowNo.setEnabled(true); edFlowNo.setText(""); } } }); } @Override protected void fillData() { clearDetail(); setDetail(); setInfo(""); if(validResult!=null){ setInfo("入库 "+ validResult.toString()); } } StockInDetailPackBarcode getCurrentObj(){ if(mDatas.size()==0){ return new StockInDetailPackBarcode(); } currentPage=currentPage<0?0:currentPage; currentPage=currentPage>mDatas.size()?mDatas.size()-1:currentPage; return mDatas.get(currentPage); } private void validInputStatus( StockInDetailPackBarcode ssd ){ boolean canValid =ssd!=null &&ssd.getPreState()==0; edSeedsCnt.setEnabled(canValid); edFlowNo.setEnabled(canValid); edProductDate.setEnabled(canValid); btnConfirm.setEnabled(canValid); } private String lastCustId=""; private void setDetail() { if(mDatas.size()==0){ return; } StockInDetailPackBarcode ssd = getCurrentObj(); validInputStatus(ssd); if(!ssd.getCustomerId().equalsIgnoreCase(lastCustId)){ lastCustId=ssd.getCustomerId(); this.edFlowNo.setText(""); } tvPages.setText(currentPage+1 +"/" +mDatas.size()); // tvBarcode.setText(ssd.getBarcode()); tvUnit.setText(ssd.getUnit()); //edProductDate.setText(ssd.getProductDate()); tvGoodsName.setText(ssd.getGoodsName()); // tvSpec.setText(""); tvValidCnt.setText(ssd.getNewArriveCount()); //商品汇总订单总数 tvCustomer.setText( ssd.getCustName()); tvSeedsTotalCnt.setText(ssd.getValidCount()); //商品汇总已分数量 tvOrderCnt.setText(ssd.getOrderCount()+""); tvBigCount.setText(ssd.getBigCount()+""); tvSeedsCnt.setText(ssd.getSeeded()+"");//店铺已分数量 edSeedsCnt.setText((ssd.getOrderCount()-ssd.getSeeded())+""); tvUnit2.setText(ssd.getMinOperateUnit()); if(connectBlueWeight(edSeedsCnt,ssd.getMinOperateUnit(),edFlowNo)){ }else if( !edFlowNo.isEnabled()){ edFlowNo.setEnabled(true); } edProductDate.setText(getDateStr()); edFlowNo.setEnabled(true); chkPrint.setEnabled(true); /* if( connectBlueWeight(edSeedsBulkCnt,ssd.getMinOperateUnit(),edFlowTo) ){ edSeedsBoxCnt.setText(""); edSeedsBoxCnt.setEnabled(false); chkPrint.setChecked(true); chkPrint.setEnabled(false); } */ if(chkPrint.isChecked() ) { edFlowNo.setEnabled(false); if (edFlowNo.getText().toString().length() == 0) edFlowNo.setText(getRandomFlowNo()); } } @OnClick({R.id.btnConfirm,R.id.btnNextPage,R.id.btnLastPage,R.id.rdByCust,R.id.rdByGoods,R.id.btnQuery}) void btnOnClick(View view) { validResult=null; switch (view.getId()) { case R.id.btnConfirm: doStockIn(); break; case R.id.btnNextPage: goNexPage(); break; case R.id.btnLastPage: goLastPage(); break; case R.id.rdByCust: switchRadio(R.id.rdByCust);; break; case R.id.rdByGoods: switchRadio(R.id.rdByGoods);; break; case R.id.btnQuery: popBack(); break; } } int lastRadio =R.id.rdByCust; private void switchRadio(int rd) { if(lastRadio!=rd){ lastRadio =rd; currentPage=0; edBarcode.setText(""); doGetValidInDetail(); } } private void goLastPage() { if(currentPage>0) { currentPage--; } fillData(); } private void goNexPage() { if(currentPage0; }catch (Exception er) { edSeedsCnt.requestFocus(); return false; } } void clearDetail(){ // currentPage=0; tvPages.setText("/"); tvBarcode.setText(""); tvUnit.setText(""); //edProductDate.setText(""); tvGoodsName.setText(""); // tvSpec.setText(""); tvValidCnt.setText(""); tvCustomer.setText(""); tvSeedsTotalCnt.setText(""); tvOrderCnt.setText(""); edSeedsCnt.setText(""); btnLastPage.setEnabled(currentPage>0); btnNextPage.setEnabled(currentPage+1 map; void doStockIn(){ map = buildParameters(); if(map.size()==0) { edPreinNo.selectAll(); edPreinNo.requestFocus(); setInfo(" 请扫描到货单 "); return; } if(!validInPut()){ return; } doStockIn(map);; } private Map buildParameters() { StockInDetailPackBarcode ssd = getCurrentObj(); //validIn(preInNo, "ZT666.", goodsId, batchCount, 0, skuValues, true, true,0,0,false,false,true,null,0,outDetailId, purch_d_id) Map map = new HashMap<>() ; if(ssd.getId()==0){ return map; } map.put("preInNo",ssd.getPreInOrderNo()); map.put("flowNo",edFlowNo.getText().toString().trim().replaceAll("\\r|\\n","")); map.put("goodsId",ssd.getGoodsId()); map.put("batchCount",getBatchCount()+""); map.put("prdDate", edProductDate.getText().toString()); map.put("isPass",true+""); map.put("isIsuLocations","true"); map.put("isZhitong", "true"); map.put("outPickDetailId", ssd.getOutPickDetailId()+""); map.put("purch_d_id", ssd.getId()+""); map.put("zhitongPartion", "666"); map.put("isOnce",chkOnce.isChecked()+""); // String evdate =edValidDate.getText().toString(); return map; } private boolean validInPut() { if(edFlowNo.getText().toString().isEmpty()){ setInfo("请扫描容器码" ); edFlowNo.selectAll(); edFlowNo.requestFocus(); return false; } float inCnt = getBatchCount(); if(inCnt<=0){ setInfo(" 入库数量需大于零 " ); } /* else if(inCnt > Float.valueOf( getCurrentObj().getNewArriveCount())-Float.valueOf( getCurrentObj().getNewValidCount())){ setInfo(" 入库数量不能大于可用数量 " ); }*/ else{ return true; } edSeedsCnt.selectAll(); edSeedsCnt.requestFocus(); return false; } float getBatchCount(){ //批次数量 if(TextUtils.isEmpty(edSeedsCnt.getText().toString())){ edSeedsCnt.setText("0"); } try { return Float.valueOf(edSeedsCnt.getText().toString()) /weightRate; }catch (Exception er){ } return 0; } private void doStockIn( Map map ) { validResult=null; BookSubscribe.stockIn(map, new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() { @Override public void onSuccess(String result) { } @Override public void onSuccess(JSONObject jsonObject) { try { int stockInResultCode = jsonObject.getInt("Code"); //String stockInResult = jsonObject.getString("Message"); validResult = Enums.enumValidInResult.values()[stockInResultCode]; if(validResult== Enums.enumValidInResult.成功){ Log.d(TAG, "onSuccess: to doGetStockPreInItem"); if( chkPrint.isChecked() || connectBlueWeight(edSeedsCnt,getCurrentObj().getMinOperateUnit(),null)) { printStockInItem(getCurrentObj().getCustNameWithLineOrde(), getCurrentObj().getGoodsName(), map.get("batchCount"), getCurrentObj().getMinOperateUnit(), edFlowNo.getText().toString(), Enums.enumWhType.直通收货区.toString()); } doGetValidInDetail(); } } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "onSuccess: 解析失败", e); } Log.d(TAG, "progress: progress to hide"); handler.sendEmptyMessage(1); } @Override public void onFault(String errorMsg) { //tvIp.setText("failure"); //失败 Log.e(TAG, "error on get firstpage: " + errorMsg); failureMsg =errorMsg; handler.sendEmptyMessage(2); } }, this.getActivity(),true)); } @Override public void printDone(){ super.printDone(); // doPandianItem(map); } }