/** * 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; }
/** * Get the current stock levels, does not take into account the current range * @param $result * @return mixed */ public function getStockLevels($result) { $stats = []; $stockMdl = new StockModel(); $stocks = $stockMdl->get(null, null, true); if ($stocks === false) { $result['error'] = "Error getting stock data: " . $stockMdl->errorInfo; } foreach ($stocks as $stock) { $stats[$stock['id']] = new stdClass(); if ($stock['locationid'] == 0) { $stats[$stock['id']]->location = "Warehouse"; } else { $stats[$stock['id']]->location = $stock['location']; } $stats[$stock['id']]->name = $stock['name']; $stats[$stock['id']]->supplier = $stock['supplier']; $stats[$stock['id']]->stocklevel = $stock['stocklevel']; $stats[$stock['id']]->stockvalue = $stock['stockvalue']; } $result['data'] = $stats; return $result; }
/** * @param $result * @return mixed Returns an array of stock. Each row is a certain item & location ID. */ public function getStock($result) { $stockMdl = new StockModel(); $stocks = $stockMdl->get(); if (is_array($stocks)) { $stockdata = []; foreach ($stocks as $stock) { $stockdata[$stock['id']] = $stock; } $result['data'] = $stockdata; } else { $result['error'] = $stockMdl->errorInfo; } return $result; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $stok = StockModel::find($id); $stok->delete(); // notif Session::flash('message', 'data di hapus'); // redirect return Redirect::to('stok'); }