Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. @Override
  2. public void afterTextChanged(Editable s) {
  3.  
  4. textwatcheritem = clicked-1 ;
  5. int i = 0;
  6. if(s == etproduct[textwatcheritem].getEditableText()){
  7. i = 1;
  8. }else if(s == etquantity[textwatcheritem].getEditableText()){
  9. i = 2 ;
  10. }
  11. switch(i)
  12. {
  13. case 1:
  14. String clientname = edclientname.getText().toString();
  15. if(TextUtils.isEmpty(clientname)){
  16. etproduct[textwatcheritem].clearFocus();
  17. edclientname.requestFocus();
  18. Toast.makeText(getActivity(), getResources().getString(R.string.strgetclient), Toast.LENGTH_LONG).show();
  19. } else{
  20. clientname = edclientname.getText().toString();
  21. customerid = String.valueOf(Customers.getCustomerid(getActivity(), clientname));
  22.  
  23. }
  24. break;
  25. case 2:
  26. String productname = etproduct[textwatcheritem].getText().toString();
  27. if(TextUtils.isEmpty(productname)){
  28. etproduct[0].requestFocus() ;
  29. Toast.makeText(getActivity(), getResources().getString(R.string.strfilldata), Toast.LENGTH_LONG).show();
  30. } else{
  31. productname = etproduct[textwatcheritem].getText().toString();
  32. if(Validating.areSet(productname)) {
  33. int qu = Stock.getAllStockQuantity(getActivity(), productname);
  34. if(qu < 1){
  35. Toast.makeText(getActivity(), "this product is sold out", Toast.LENGTH_LONG).show();
  36. etproduct[textwatcheritem].findFocus();
  37. } else {
  38. int userquantity = 0;
  39. String qt = etquantity[textwatcheritem].getText().toString();
  40. if(Validating.areSet(qt)) {
  41. userquantity = Integer.parseInt(qt) ;
  42. if(userquantity > qu)
  43. {
  44. Toast.makeText(getActivity(), productname +" "+getResources().getString(R.string.strsalesquantityerror1)+
  45. " "+qu+" "+getResources().getString(R.string.strsalesquantityerror2), Toast.LENGTH_LONG).show();
  46. etquantity[textwatcheritem].setText("");
  47. etproduct[textwatcheritem].findFocus();
  48. return;
  49. } else {
  50. // price and taxes of the respective product chosen
  51. double pr = Stock.getUnitPrice(getActivity(), productname);
  52. double tx = Stock.getTax(getActivity(), productname);
  53. int proid = Stock.getStockid(getActivity(), productname);
  54. //getting the final price tax inc/exclusive times quantity
  55. double grandtotal = Double.parseDouble(Constants.getPriceAfterBeforeTax(pr, tx, 0)) * userquantity ;
  56. double grandtotalwithnotax = Double.parseDouble(Constants.getPriceAfterBeforeTax(pr, tx, 1))* userquantity;
  57.  
  58. if(userquantity == 0){
  59. etprice[textwatcheritem].setText("0.0") ;
  60. }else{
  61. //set the price of the current item
  62. String totalp = String.format("%.02f", grandtotal);
  63. etprice[textwatcheritem].setText(totalp) ;
  64. //this shit works
  65. double item_sale_price = pr * userquantity ;
  66. orderQuantity.add(userquantity);
  67. String orderdetails = proid+"-"+ userquantity+"-" + item_sale_price+"-"+tx+"-"+grandtotal+ "-"+productname+ "-"+grandtotalwithnotax;
  68. orderDetailsList.add(orderdetails);
  69. }
  70. double reportdata = 0 ;
  71. String strfinalprice = txreportdata.getText().toString() ;
  72. if(TextUtils.isEmpty(strfinalprice)) {
  73. reportdata = 0 ;
  74. } else {
  75. reportdata = Double.parseDouble(strfinalprice) ;
  76. }
  77. double total = grandtotal + reportdata ;
  78. String totals = String.format("%.02f", total);
  79. txreportdata.setText(totals) ;
  80. }
  81. } else {
  82. etprice[textwatcheritem].setText("0.0");
  83. }
  84. }
  85. }
  86. }
  87. break;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement