Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public void checkProductQuantity(
  2. final ProductPerWarehouseResponse productPerWarehouseResponse) {
  3. List<ProductPerWarehouseResponse.Products> productResponseList = productPerWarehouseResponse.products;
  4. currentWarehouseQuantity = new SparseArray<>();
  5. for(ProductPerWarehouseResponse.Products products : productResponseList){
  6. int key = products.product.id;
  7.  
  8. //if id = 0, it is unassigned, get the first one
  9. if(products.product.warehouseInventory.size() > 0) {
  10. float quantity = products.product.warehouseInventory.get(0).quantity;
  11. currentWarehouseQuantity.put(key, quantity);
  12. }
  13. }
  14.  
  15. checkProductStockInWarehouse();
  16.  
  17. runOnUiThread(new Runnable() {
  18. public void run() {
  19. mSalesInvoiceCreateProductAdapter.notifyDataSetChanged();
  20. }
  21. });
  22. }
  23.  
  24. private void checkProductStockInWarehouse() {
  25. for(int i = 0; i<mSalesInvoice.getProducts().size(); i++){
  26. Product product = mSalesInvoice.getProducts().get(i);
  27.  
  28. BigDecimal editQuantity = BigDecimal.ZERO;
  29. int currentWarehouseId = mSalesInvoice.getWarehouse() != null ?
  30. mSalesInvoice.getWarehouse().getId() : 0;
  31. if(currentWarehouseId == product.getWarehouse() &&
  32. product.getEditQuantity() != null) {
  33. editQuantity = product.getEditQuantity();
  34. }
  35.  
  36. if(currentWarehouseQuantity != null) {
  37. boolean checkWarehouseQuantity = currentWarehouseQuantity.get(product.id) == null ||
  38. (BigDecimal.valueOf(currentWarehouseQuantity.get(product.id))
  39. .add(editQuantity))
  40. .compareTo(BigDecimal.valueOf(product.getQuantity())) < 0;
  41. if(checkWarehouseQuantity) {
  42. mSalesInvoice.getProducts().get(i).setNotEnoughStock(true);
  43. } else {
  44. mSalesInvoice.getProducts().get(i).setNotEnoughStock(false);
  45. }
  46. mProductList.set(i, mSalesInvoice.getProducts().get(i));
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement