public function createStockOnLocation($quantity, Model $location, $reason = '', $cost = 0, $aisle = null, $row = null, $bin = null)
{
try {
// We want to make sure stock doesn't exist on the specified location already
if ($this->getStockFromLocation($location)) {
$message = Lang::get('inventory::exceptions.StockAlreadyExistsException', ['location' => $location->name]);
throw new StockAlreadyExistsException($message);
}
} catch (StockNotFoundException $e) {
// A stock record wasn't found on this location, we'll create one.
$stock = $this->stocks()->getRelated()->newInstance();
$stock->setAttribute('inventory_id', $this->getKey());
$stock->setAttribute('location_id', $location->getKey());
$stock->setAttribute('quantity', 0);
$stock->setAttribute('aisle', $aisle);
$stock->setAttribute('row', $row);
$stock->setAttribute('bin', $bin);
if ($stock->save()) {
return $stock->put($quantity, $reason, $cost);
}
}
return false;
}