/**
  * Set the level of stock at a location (stocktake)
  * @param $result
  * @return mixed
  */
 public function setStockLevel($result)
 {
     // validate input
     $jsonval = new JsonValidate($this->data, '{"storeditemid":1, "locationid":1, "amount":">=1"}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     // create history record for added stock
     if ($this->createStockHistory($this->data->storeditemid, $this->data->locationid, 'Stock Added', $this->data->amount) === false) {
         $result['error'] = "Could not create stock history record";
         return $result;
     }
     if ($this->stockMdl->setStockLevel($this->data->storeditemid, $this->data->locationid, $this->data->amount) === false) {
         $result['error'] = "Could not add stock to the location";
     }
     // Success; log data
     Logger::write("Stock Level Set", "STOCK", json_encode($this->data));
     return $result;
 }