public function search($params) { $query = Items::find()->where(['play_status' => 1]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'tags', $this->tags]); return $dataProvider; }
/** * Случайный айтем * @return string */ function actionRandItem() { //return 45; $thoughts = Items::find()->where("source_id = 27 or source_id = 17 or\n source_id = 37 or source_id = 336 or source_id = 528 or cat_id = 104 or cat_id = 94")->andWhere('cens = 0')->orderBy('id ASC')->all(); $random_ind = rand(0, count($thoughts) - 1); if ($thoughts[$random_ind]) { return "document.getElementById('rand').innerHTML = \"" . addcslashes(nl2br($thoughts[$random_ind]->text, false), "\r\n\"\\'") . "<br><span style='font-size: 15px'> (" . $thoughts[$random_ind]->source->title . " - " . $thoughts[$random_ind]->source->author->name . ")</span>" . "\";"; } else { return "document.getElementById('rand').innerHTML = 'Доброго Вам Времени!';"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Items::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'quantity' => $this->quantity]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'remarks', $this->remarks]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Items::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category' => $this->category, 'type' => $this->type, 'weight' => $this->weight, 'price' => $this->price, 'quantity' => $this->quantity, 'additionDate' => $this->additionDate]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'color', $this->color])->andFilterWhere(['like', 'dimensions', $this->dimensions])->andFilterWhere(['like', 'comment', $this->comment])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
public function destroy($id) { $ItemCategories = ItemCategories::findOrFail($id); $items = Items::where(['category_id' => $id])->get(); Helper::add($id, 'deleted items category ' . $ItemCategories->title); if (count($items) > 0) { $category = ItemCategories::where(['title' => 'Uncategorized'])->first(); if (!$category) { $category = ItemCategories::create(['title' => 'Uncategorized']); } Items::where(['category_id' => $id])->update(['category_id' => $category->id]); } if ($ItemCategories->title == 'Uncategorized' && count($items) > 0) { } else { $ItemCategories->delete(); } Session::flash('flash_message', $this->title . ' successfully deleted!'); return Redirect::action('ItemCategoriesController@index'); }
public function update($id, Request $request) { $Units = Units::findOrFail($id); $item = Items::findOrFail($Units->item_id); $this->validate($request, ['title' => 'required|unique:units|max:100']); $input = $request->all(); Helper::add($id, 'updated unit ' . $Units->title . ' for item ID ' . $input['item_id']); if (array_key_exists('default', $input)) { ItemUnits::where(['default' => 1, 'item_id' => $input['item_id']])->where('id', '!=', $id)->update(['default' => 0]); ItemUnits::where(['item_id' => $input['item_id']])->update(['factor' => DB::raw('factor/' . $input['factor'])]); Helper::add($id, 'changed item ' . $item->title . '(ID ' . $input['item_id'] . ') default unit to ' . $Units->title); StockItem::where(['item_id' => $input['item_id']])->update(['stock' => DB::raw('stock/' . $input['factor'])]); RecipeItems::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]); Menu::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]); ItemPurchases::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]); StockCheck::where(['item_id' => $input['item_id']])->update(['before' => DB::raw('`before` / ' . $input['factor']), 'after' => DB::raw('`after` / ' . $input['factor'])]); $input['default'] = 1; } $Units->fill($input)->save(); Session::flash('flash_message', $this->title . ' successfully added!'); return Redirect::action('UnitsController@index'); }
public function actionAdmingetallitems() { $rightNowUserId = Yii::$app->user->identity->XH_ID; $rightNowUserName = Yii::$app->user->identity->Name; $item = new Items(); $nowpage = $_GET['nowpage']; $allpage = $_GET['allpage']; $countallpages = $item->getItempages(5); if ($allpage > $countallpages || $allpage < 0) { $result = '{"success":false,"msg":"查询出错","userIdNow":"' . $rightNowUserId . '","userName":"******","allpage":"' . $countallpages . '"}'; return $result; } $result = $item->AdminAllItems($nowpage, 5); if ($result) { $msg = '<thead><tr><td>编号</td><td>状态</td><td>姓名</td><td>项目名</td><td>时间</td><td>通过|不通过|详细</td></tr></thead><tbody>'; foreach ($result as $key => $value) { $msg .= '<tr><td>' . ($key + 1) . '</td><td>' . $this->adminStatusThatHumanCanRead($value['status']) . '</td><td>' . $value['username'] . '</td><td>' . $value['Item_Name'] . '</td><td>' . $value['Date'] . '</td><td><div class=\\"Set_dele glyphicon glyphicon-ok\\" onclick=\\"ItemPass(' . $value['Item_Id'] . ')\\"></div>|<div class=\\"Set_dele glyphicon glyphicon-remove\\" onclick=\\"ItemFail(' . $value['Item_Id'] . ')\\"></div>|<div class=\\"Set_dele glyphicon glyphicon-eye-open\\" onclick=\\"ItemDescribe(' . $value['Item_Id'] . ')\\"></div></td></tr>'; } echo '{"success":true,"msg":"' . $msg . '","userIdNow":"' . $rightNowUserId . '","userName":"******","allpage":"' . $countallpages . '"}'; } else { echo '{"success":true,"msg":"没有项目","userIdNow":"' . $rightNowUserId . '","userName":"******","allpage":"' . $countallpages . '"}'; } }
public function actionItems() { $model = Items::find()->orderBy(['id' => SORT_DESC])->limit(10)->all(); return $this->renderPartial('latest-items', ['model' => $model]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $RecipeItems = RecipeItems::findOrFail($id); $recipe = Recipes::findOrFail($RecipeItems->recipe_id); if ($RecipeItems->type == 'recipe') { $item = Recipes::findOrFail($RecipeItems->sub_recipe); } else { $item = Items::findOrFail($RecipeItems->item_id); } $RecipeItems->delete(); Helper::add($id, 'deleted ' . $RecipeItems->type . ' ' . $item->title . ' (ID ' . $RecipeItems->id . ') from recipe ' . $recipe->title . ' (ID ' . $recipe->id . ')'); Session::flash('flash_message', $this->title . ' successfully deleted!'); return Redirect::action('RecipeItemsController@index', ['recipe_id' => $recipe->id]); }
public function loadModel($id) { $model = Items::findOne($id); if ($model === null) { throw new \yii\web\HttpException(404, 'The requested page does not exist.'); } return $model; }
public function delete() { Items::deleteItem(); $item_listuuid = Request::segment(2); return redirect('/list/' . $item_listuuid); }
public function actionItemprice() { if (\filter_input(INPUT_POST, 'item')) { $item_id = filter_input(INPUT_POST, 'item'); $model = Items::findOne($item_id); if (!empty($model)) { return json_encode($model->price); } } }
/** * Finds the Items model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Items the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Items::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Формирование рандомного (но с учетом статуса записи) плейлиста для радио */ public function actionMakeRadioPlayListRandChess() { $f = fopen("/home/romanych/radio/dio/playlist.txt", 'w'); $arr = []; $dibilizmy = Items::find()->where(["source_id" => 17])->all(); shuffle($dibilizmy); $limerik = Items::find()->where(["source_id" => 27])->all(); shuffle($limerik); $cavers = Items::find()->where(["source_id" => 38])->all(); shuffle($cavers); $frazy = Items::find()->where("source_id = 181 or source_id = 37 or source_id = 30 or source_id = 29 or source_id = 25 or source_id = 20")->all(); shuffle($frazy); $peredelki = Items::find()->where(["source_id" => 19])->all(); shuffle($peredelki); $pesni = Items::find()->where(["source_id" => 6])->all(); shuffle($pesni); for ($i = 0; $i < 100; $i++) { if (isset($dibilizmy[$i])) { array_push($arr, $dibilizmy[$i]); } if (isset($limerik[$i])) { array_push($arr, $limerik[$i]); } if (isset($cavers[$i])) { array_push($arr, $cavers[$i]); } if (isset($frazy[$i])) { array_push($arr, $frazy[$i]); } if (isset($peredelki[$i])) { array_push($arr, $peredelki[$i]); } if (isset($pesni[$i])) { array_push($arr, $pesni[$i]); } } foreach ($arr as $item) { if (strstr($item->audio_link, '/music')) { $one = str_replace('/music', 'music', $item->audio_link); fwrite($f, "/home/romanych/" . $one . PHP_EOL); } else { fwrite($f, "/home/romanych/Музыка/Thoughts_and_klassik/new_ideas/" . $item->audio_link . PHP_EOL); } } fclose($f); // print_r($arr); }
/** * Выборка для случайного концерта * @return string */ function actionConcert() { if ($user = Yii::$app->getRequest()->getQueryParam('user')) { if (!$user) { return 'Доступ запрещн!'; } // $user = Yii::$app->getRequest()->getQueryParam('user'); if (Items::find()->where(['is_next' => 1])->one()) { $item = Items::find()->where(['is_next' => 1])->one(); $song_id = $item->id; } else { $song_id = 100; } $songs = []; //return $song_id; $songs1 = Items::find()->where("(source_id = 6 or source_id = 40) and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all(); $songs2 = Items::find()->where("(source_id = 19 or source_id = 41) and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all(); $songs3 = Items::find()->where("source_id = 38 and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all(); $songs4 = Items::find()->where("(source_id = 29 or source_id = 326 or source_id = 526) and id < {$song_id} and published = 1")->limit(1)->orderBy('id DESC')->all(); $songs = array_merge($songs1, $songs2, $songs3, $songs4); shuffle($songs); //return var_dump($songs); //$choosen_songs = []; foreach ($songs as $song) { try { $items_records = []; $tags = explode(',', $song->tags); $rand_tag = $tags[mt_rand(0, count($tags) - 1)]; $this->rand_tag[] = $rand_tag; $query = new Query(); // $search_result = $query_search->from('siteSearch')->match($q)->all(); // поиск осуществляется по средством метода match с переданной поисковой фразой. $query_items_ids = $query->from('items')->match($rand_tag)->all(); //return var_dump($query_items_ids); foreach ($query_items_ids as $arr_item_rec) { foreach ($arr_item_rec as $id) { $item = Items::findOne((int) $id); if ($item->cat_id == 93 || $item->cat_id == 104 || $item->cat_id == 105 || $item->cat_id == 143 || $item->cat_id == 136) { $items_records[] = Items::findOne((int) $id); } } } //return var_dump($items_records[mt_rand(0,count($items_records)-1)]->text); if (empty($items_records)) { continue; } $rand_index = mt_rand(0, count($items_records) - 1); $song->phrase = $items_records[$rand_index]->text; if (isset($items_records[$rand_index + 1]) && $song->phrase != $song->phrase2) { $song->phrase2 = $items_records[$rand_index + 1]->text; } else { $song->phrase2 = $items_records[0]->text; } //return $song->phrase.'<br>'.$song->phrase2; //return var_dump($song); $this->choosen_songs[] = $song; } catch (\ErrorException $e) { return $e->getMessage(); } } //exit; //return var_dump($this->choosen_songs); return $this->renderPartial('concert', ['songs' => $this->choosen_songs, 'tags' => $this->rand_tag]); } }
public function assign($id) { $menu = Menu::findOrFail($id); $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); return view('Menus.assign')->with(array('title' => $this->title, 'item' => $menu, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units)); }
public function init() { $list = Lists::getList(); $items = Items::getItems(); return view('list')->with('controllerFunction', 'show')->with('list', $list)->with('items', $items); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $item_purchase = ItemPurchases::findOrFail($id); $purchase = $item_purchase->purchase()->first(); $type = $item_purchase->type; if ($type == 'item') { $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; $items_units['item_to_unit'][$item->id] = $item->unit()->first()->id; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); if ($select_items) { return view('ItemPurchases.edit_item')->with(array('title' => $this->title, 'purchase' => $purchase, 'items' => $select_items, 'items_units' => $items_units, 'type' => $type, 'item' => $item_purchase)); } else { Session::flash('flash_message', 'It looks like you have used all possible products in your invoice.'); return Redirect::action('ItemPurchasesController@index', $purchase->id); } } else { return view('ItemPurchases.edit_custom')->with(array('title' => $this->title, 'purchase' => $purchase, 'type' => $type, 'item' => $item_purchase)); } }
public function edit($id) { $item = Items::findOrFail($id); $other = $item->units()->where(['default' => 0])->first(); $actions = ['add' => 'Add', 'reduce' => 'Reduce by', 'change' => 'Change to']; $other_units = []; if ($other) { foreach ($item->units()->where(['default' => 0])->get() as $unit) { $other_units[$unit->id] = $unit->unit()->first()->title; } } $currentPeriodId = Helper::periodAfterId(Helper::defaultPeriodId()); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } return view('StockCheck.edit')->with(array('title' => $this->title, 'item' => $item, 'default' => $item->units()->where(['default' => 1])->first(), 'other' => $other, 'actions' => $actions, 'other_units' => $other_units, 'period' => $currentPeriodId, 'stock' => StockCheck::select(['stock_items.*', 'stock_checks.*'])->join('stock_items', 'stock_checks.stock_item_id', '=', 'stock_items.id')->where(['stock_checks.item_id' => $id, 'stock_items.stock_period_id' => $currentPeriodId])->orderBy('stock_checks.created_at', 'DESC')->get(), 'stocks_list' => $period_list)); }
public function show($id) { $item = Items::with('recipes')->with('purchases')->findOrFail($id); $history = History::where('message', 'LIKE', '%(ID ' . $id . ')%')->where('action', '=', 'App\\Http\\Controllers\\StockCheckController@store ')->get(); echo '<pre>'; echo $history->count(); echo 'id: ' . $id; echo '</pre>'; return view('Items.show')->with(array('title' => $this->title, 'item' => $item, 'history' => $history)); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $waste = Wastes::findOrFail($id); $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); $select_menus = Menu::orderBy('title', 'ASC')->lists('title', 'id'); $select_reasons = WasteReasons::orderBy('reason', 'ASC')->lists('reason', 'id'); return view('Wastes.edit')->with(array('title' => $this->title, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units, 'menus' => $select_menus, 'period' => $currentPeriodId, 'stocks_list' => $period_list, 'reasons' => $select_reasons, 'waste' => $waste)); }
public function actionTestitem() { $item = new Items(); $item->searchAllItems(); }
/** * @return \yii\db\ActiveQuery */ public function getItems() { return $this->hasMany(Items::className(), ['play_status' => 'id']); }
private function getData($stock, $category) { $last_period = $stock; $current_period = Helper::periodAfterId($last_period); $item_purchases = []; $last_stock = []; $current_stock = []; $item_sales = []; $item_wastes = []; $items = []; $wastage = []; $sales_chart = []; $items_without_price = 0; $period = null; if ($last_period) { $purchases = Purchases::orderBy('date_created', 'ASC')->where(['stock_period_id' => $last_period])->get(); foreach ($purchases as $purchase) { foreach ($purchase->purchases()->get() as $itemPurchase) { if (array_key_exists($itemPurchase->item_id, $item_purchases)) { $item_purchases[$itemPurchase->item_id]['value'] += $itemPurchase->value; $item_purchases[$itemPurchase->item_id]['occurrences']++; $item_purchases[$itemPurchase->item_id]['price'] += $itemPurchase->value == 0 ? 0 : $itemPurchase->price / $itemPurchase->value; } else { $item_purchases[$itemPurchase->item_id]['value'] = $itemPurchase->value; $item_purchases[$itemPurchase->item_id]['price'] = $itemPurchase->value == 0 ? 0 : $itemPurchase->price / $itemPurchase->value; $item_purchases[$itemPurchase->item_id]['occurrences'] = 1; } } } foreach ($item_purchases as $key => $purchase) { $item_purchases[$key]['price'] = $purchase['price'] / $purchase['occurrences']; } $last_stock_items = StockItem::where(['stock_period_id' => $last_period])->get(); foreach ($last_stock_items as $si) { if (array_key_exists($si->item_id, $last_stock)) { $last_stock[$si->item_id] += $si->stock; } else { $last_stock[$si->item_id] = $si->stock; } } $current_stock_items = StockItem::where(['stock_period_id' => $current_period])->get(); foreach ($current_stock_items as $si) { if (array_key_exists($si->item_id, $current_stock)) { $current_stock[$si->item_id] += $si->stock; } else { $current_stock[$si->item_id] = $si->stock; } } $sales = Sales::where(['stock_period_id' => $last_period])->get(); foreach ($sales as $sale) { foreach ($sale->sales()->orderBy('quantity', 'DESC')->get() as $sale_item) { $menu = $sale_item->menu()->first(); if ($menu) { $color = $this->rand_color(); $sales_chart[$menu->id] = ['value' => $sale_item->quantity, 'color' => $color, 'highlight' => $this->alter_brightness($color, 20), 'label' => $menu->title]; if ($menu->type == 'item') { if (array_key_exists($menu->item_id, $item_sales)) { $item_sales[$menu->item_id] += $menu->value * $sale_item->quantity; } else { $item_sales[$menu->item_id] = $menu->value * $sale_item->quantity; } } elseif ($menu->type == 'recipe') { $recipe = $menu->recipe()->first(); if ($recipe) { $usage = $this->countUsageFromRecipe($recipe); foreach ($usage as $key => $use) { if (array_key_exists($key, $item_sales)) { $item_sales[$key] += $sale_item->quantity * $use; } else { $item_sales[$key] = $sale_item->quantity * $use; } } } } } } } $wastes = Wastes::where(['stock_period_id' => $last_period])->get(); foreach ($wastes as $waste) { if (array_key_exists($waste->reason()->first()->id, $wastage)) { $wastage[$waste->reason()->first()->id]['value'] = $wastage[$waste->reason()->first()->id]['value'] + 1; } else { $color = $this->rand_color(); $wastage[$waste->reason()->first()->id] = ['value' => 1, 'color' => $color, 'highlight' => $this->alter_brightness($color, 20), 'label' => $waste->reason()->first()->reason]; } if ($waste->type == 'item') { if (array_key_exists($waste->item_id, $item_wastes)) { $item_wastes[$waste->item_id] += $waste->value; } else { $item_wastes[$waste->item_id] = $waste->value; } } elseif ($waste->type == 'recipe') { $recipe = $waste->recipe()->first(); if ($recipe) { $usage = $this->countUsageFromRecipe($recipe); foreach ($usage as $key => $use) { if (array_key_exists($key, $item_wastes)) { $item_wastes[$key] += $waste->recipe_count * $use; } else { $item_wastes[$key] = $waste->recipe_count * $use; } } } } elseif ($waste->type == 'menu') { $menu = $waste->menu()->first(); if ($menu) { if ($menu->type == 'item') { if (array_key_exists($menu->item_id, $item_wastes)) { $item_wastes[$menu->item_id] += $waste->menu_count * $menu->value; } else { $item_wastes[$menu->item_id] = $waste->menu_count * $menu->value; } } elseif ($menu->type == 'recipe') { $recipe = $menu->recipe()->first(); if ($recipe) { $usage = $this->countUsageFromRecipe($recipe); foreach ($usage as $key => $use) { if (array_key_exists($key, $item_wastes)) { $item_wastes[$key] += $waste->menu_count * $use; } else { $item_wastes[$key] = $waste->menu_count * $use; } } } } } } } } $all_items = Items::all(); $variance = 0; $count = 0; foreach ($all_items as $item) { if (!array_key_exists($item->category()->first()->id, $items)) { $items[$item->category()->first()->id]['category'] = $item->category()->first()->title; $items[$item->category()->first()->id]['variance'] = 0; $items[$item->category()->first()->id]['items'] = []; } $current_item = []; //$items[$item->id]['object'] = $item; $current_item['title'] = $item->title; $current_item['units'] = $item->units()->where(['default' => 1])->first()->unit()->first()->title; $current_item['wastage'] = array_key_exists($item->id, $item_wastes) ? $item_wastes[$item->id] : 0; $current_item['last_stock'] = array_key_exists($item->id, $last_stock) ? $last_stock[$item->id] : 0; $current_item['current_stock'] = array_key_exists($item->id, $current_stock) ? $current_stock[$item->id] : 0; if (array_key_exists($item->id, $item_purchases)) { $current_item['purchases'] = $item_purchases[$item->id]; } else { $price = 0; $item_price = ItemPurchases::where(['item_id' => $item->id])->orderBy('created_at', 'DESC')->first(); if ($item_price) { $value = $item_price->value; if ($value == 0) { $value = 1; } $price = $item_price->price / $value; } else { if ($item->price) { $price = $item->price; } else { $items_without_price++; } } $current_item['purchases'] = ['value' => 0, 'price' => $price, 'occurrences' => 0]; } $current_item['sales'] = array_key_exists($item->id, $item_sales) ? $item_sales[$item->id] : 0; $current_item['must_stock'] = $current_item['last_stock'] + $current_item['purchases']['value'] - $current_item['sales'] - $current_item['wastage']; $current_item['stock_difference'] = $current_item['current_stock'] - $current_item['must_stock']; $current_item['variance'] = round($current_item['stock_difference'] * $current_item['purchases']['price'], 2); $variance += $current_item['variance']; $items[$item->category()->first()->id]['variance'] += $current_item['variance']; $items[$item->category()->first()->id]['items'][$item->id] = $current_item; $count++; } return $category && array_key_exists($category, $items) ? $items[$category] : $items; }
/** * @return \yii\db\ActiveQuery */ public function getItem() { return $this->hasOne(Items::className(), ['id' => 'item_id']); }
public function actionGetitemuser() { $itemid = $_GET['itemid']; $item = new Items(); $content = $item->getitemuser($itemid); return $content; }
function getDecendants($nodeId) { $node = Items::find($nodeId); if (!$node) { return false; } return $node->getDescendants(); }