/**
  * Returns the last stock-level in the stock-history, using the internal
  * $_counter-array.
  * Uses _checkUnitsSet-method to make sure a product was already set!
  *
  * @return int last stock level, if never adjusted the current stock level is returned
  */
 public function getLastStock(Unit $unit, Location\Location $location)
 {
     $this->_checkUnitsSet();
     if (!isset($this->_counter[$unit->id][$location->name])) {
         $this->_counter[$unit->id][$location->name] = $unit->getStockForLocation($location);
     }
     return $this->_counter[$unit->id][$location->name];
 }
 /**
  * Creates an adjustment for the given unit and location, with a new
  * value the stock level will be set to.
  * No conversion into a positive value will be made!
  *
  * @param Unit 		$unit 		the unit the adjustment will effect
  * @param Location 	$location 	the stock location
  * @param int 		$value 		the new stock level
  *
  * @throws \IllegalArgumentException if the value is negative
  *
  * @return StockManager $this for chainability
  */
 public function set(Unit $unit, Location $location, $value)
 {
     if ($value < 0) {
         throw new \IllegalArgumentException("Value set for stock adjustment must be positive!");
     }
     $adjustment = new Adjustment\Adjustment();
     $curStockLevel = $unit->getStockForLocation($location);
     $adjustment->unit = $unit;
     $adjustment->location = $location;
     $adjustment->delta = $value - $curStockLevel;
     $this->_saveNewAdjustment($adjustment);
     return $this;
 }
 public function saveStockForLocation(Unit $unit, Location $location)
 {
     return $this->_saveStockLevel($unit->id, $location->name, $unit->getStockForLocation($location));
 }