void WarehouseStore::applyRetrieveReservation(GoodStock &stock, const long reservationID) { GoodStock reservedStock = getRetrieveReservation(reservationID, true); if (stock._goodType != reservedStock._goodType) { THROW("GoodType does not match reservation"); } if (stock._maxQty < stock._currentQty + reservedStock._currentQty) { THROW("Quantity does not match reservation"); } int amount = reservedStock._currentQty; // std::cout << "WarehouseStore, retrieve qty=" << amount << " resID=" << reservationID << std::endl; // first we look at the half filled subTiles for (std::vector<WarehouseTile>::iterator subTilesIt=_warehouse->_subTiles.begin(); subTilesIt!=_warehouse->_subTiles.end(); ++subTilesIt) { if (amount == 0) { break; } WarehouseTile &subTile = *subTilesIt; if (subTile._stock._goodType == stock._goodType && subTile._stock._currentQty < subTile._stock._maxQty) { int tileAmount = std::min(amount, subTile._stock._currentQty); // std::cout << "retrieve from half filled" << std::endl; stock.addStock(subTile._stock, tileAmount); amount -= tileAmount; } } // then we look at the filled subTiles for (std::vector<WarehouseTile>::iterator subTilesIt=_warehouse->_subTiles.begin(); subTilesIt!=_warehouse->_subTiles.end(); ++subTilesIt) { if (amount == 0) { break; } WarehouseTile& subTile = *subTilesIt; if (subTile._stock._goodType == stock._goodType) { int tileAmount = std::min(amount, subTile._stock._currentQty); // std::cout << "retrieve from filled" << std::endl; subTile._stock.addStock(stock, tileAmount); amount -= tileAmount; } } }
bool Storage::applyRetrieveReservation(good::Stock& stock, const int reservationID) { good::Stock reservedStock = getRetrieveReservation(reservationID, true); if (stock.type() != reservedStock.type()) { Logger::warning( "SimpleGoodStore:GoodType does not match reservation"); return false; } if( stock.capacity() < stock.qty() + reservedStock.qty()) { Logger::warning( "SimpleGoodStore:Quantity does not match reservation"); return false; } int amount = reservedStock.qty(); good::Stock& currentStock = getStock(reservedStock.type()); currentStock.pop( amount ); stock.push( amount ); return true; }
void SimpleGoodStore::applyRetrieveReservation(GoodStock &stock, const long reservationID) { GoodStock reservedStock = getRetrieveReservation(reservationID, true); if (stock._goodType != reservedStock._goodType) { _OC3_DEBUG_BREAK_IF("SimpleGoodStore:GoodType does not match reservation"); return; } if( stock._maxQty < stock._currentQty + reservedStock._currentQty) { _OC3_DEBUG_BREAK_IF("SimpleGoodStore:Quantity does not match reservation"); return; } int amount = reservedStock._currentQty; GoodStock ¤tStock = getStock(reservedStock._goodType); currentStock._currentQty -= amount; stock._currentQty += amount; // std::cout << "SimpleGoodStore, retrieve qty=" << amount << " resID=" << reservationID << std::endl; }