Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void checkProductQuantity(
- final ProductPerWarehouseResponse productPerWarehouseResponse) {
- List<ProductPerWarehouseResponse.Products> productResponseList = productPerWarehouseResponse.products;
- currentWarehouseQuantity = new SparseArray<>();
- for(ProductPerWarehouseResponse.Products products : productResponseList){
- int key = products.product.id;
- //if id = 0, it is unassigned, get the first one
- if(products.product.warehouseInventory.size() > 0) {
- float quantity = products.product.warehouseInventory.get(0).quantity;
- currentWarehouseQuantity.put(key, quantity);
- }
- }
- checkProductStockInWarehouse();
- runOnUiThread(new Runnable() {
- public void run() {
- mSalesInvoiceCreateProductAdapter.notifyDataSetChanged();
- }
- });
- }
- private void checkProductStockInWarehouse() {
- for(int i = 0; i<mSalesInvoice.getProducts().size(); i++){
- Product product = mSalesInvoice.getProducts().get(i);
- BigDecimal editQuantity = BigDecimal.ZERO;
- int currentWarehouseId = mSalesInvoice.getWarehouse() != null ?
- mSalesInvoice.getWarehouse().getId() : 0;
- if(currentWarehouseId == product.getWarehouse() &&
- product.getEditQuantity() != null) {
- editQuantity = product.getEditQuantity();
- }
- if(currentWarehouseQuantity != null) {
- boolean checkWarehouseQuantity = currentWarehouseQuantity.get(product.id) == null ||
- (BigDecimal.valueOf(currentWarehouseQuantity.get(product.id))
- .add(editQuantity))
- .compareTo(BigDecimal.valueOf(product.getQuantity())) < 0;
- if(checkWarehouseQuantity) {
- mSalesInvoice.getProducts().get(i).setNotEnoughStock(true);
- } else {
- mSalesInvoice.getProducts().get(i).setNotEnoughStock(false);
- }
- mProductList.set(i, mSalesInvoice.getProducts().get(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement