/** * Run the database seeds. * * @return void */ public function run() { // Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/templates/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); DB::table('channel_items')->truncate(); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'MKL Mapping') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if ($row[0] != '') { if ($cnt > 0) { // dd($row); if (!ctype_digit(trim($row[4])) || !ctype_digit(trim($row[5])) || !ctype_digit(trim($row[6]))) { InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'MKL Mapping', 'remarks' => 'Invalid mapping']); } else { $channel = ''; if (trim($row[0]) != '') { $channel = Channel::where('channel_code', trim($row[0]))->first(); } $item = Item::where('sku_code', trim($row[3]))->first(); if (!empty($item)) { $item_type = ItemType::where('type', "MKL")->first(); $osa_tagging = 0; if (isset($row[7])) { $osa_tagging = trim($row[7]); } $npi_tagging = 0; if (isset($row[8])) { $npi_tagging = trim($row[8]); } ChannelItem::firstOrCreate(['channel_id' => $channel->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]); } } } $cnt++; } } } } $reader->close(); }
public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); $folderpath = base_path() . '/database/seeds/seed_files/'; $folders = File::directories($folderpath); $latest = '11232015'; foreach ($folders as $value) { $_dir = explode("/", str_replace('\\', '/', $value)); $cnt = count($_dir); $name = $_dir[$cnt - 1]; $latest_date = DateTime::createFromFormat('mdY', $latest); $now = DateTime::createFromFormat('mdY', $name); if ($now > $latest_date) { $latest = $name; } } $filePath = $folderpath . $latest . '/Masterfile.xlsx'; $reader = ReaderFactory::create(Type::XLSX); // for XLSX files $reader->open($filePath); echo 'Seeding ' . $filePath . PHP_EOL; // DB::table('other_barcodes')->truncate(); Item::where('active', 1)->update(['cleared' => 0]); foreach ($reader->getSheetIterator() as $sheet) { if ($sheet->getName() == 'Other Codes') { $cnt = 0; foreach ($sheet->getRowIterator() as $row) { if (!is_null($row[0]) && trim($row[0]) != '') { if ($cnt > 0) { $item = Item::where('sku_code', trim($row[0]))->first(); if (!empty($item)) { if ($item->cleared == 0) { OtherBarcode::where('item_id', $item->id)->delete(); $item->cleared = 1; $item->save(); } $area = Area::where('area', strtoupper($row[1]))->first(); if (!empty($item) && !empty($area)) { OtherBarcode::firstOrCreate(['item_id' => $item->id, 'area_id' => $area->id, 'other_barcode' => trim($row[2])]); } } else { // dd($row); } } $cnt++; } } } } $reader->close(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); Model::reguard(); }
/** * @param Item $item * @return array */ public function transform(Item $item) { $array = ['id' => $item->id, 'parent_id' => $item->parent_id, 'title' => $item->title, 'body' => $item->body, 'index' => $item->index, 'category_id' => $item->category_id, 'priority' => $item->priority, 'urgency' => $item->urgency, 'favourite' => $item->favourite, 'pinned' => $item->pinned, 'path' => $item->path, 'has_children' => $item->has_children, 'category' => $item->category->transform(), 'alarm' => $item->alarm, 'timeLeft' => null, 'notBefore' => $item->not_before, 'recurringUnit' => $item->recurring_unit, 'recurringFrequency' => $item->recurring_frequency, 'children' => false]; if ($item->trashed()) { $array['deleted_at'] = $item->deleted_at->format('Y-m-d H:i:s'); } return $array; }
/** * Run the database seeds. * * @return void */ public function run() { // --------------------------------------------------------------------- // CONFERENCE 4 // --------------------------------------------------------------------- $conference = Conference::find(4); $item = ['name' => 'Laptop', 'quantity' => 1]; $item = new Item($item); $item->conference()->associate($conference); $item->save(); $item = ['name' => 'Projector', 'quantity' => 1]; $item = new Item($item); $item->conference()->associate($conference); $item->save(); }
public function delete(Request $request, $id) { $b = Item::find($id); $b->name = $request->input('name'); $b->delete(); return Redirect('itemmaster'); }
/** * @return string */ public function actionIndex() { $low_stock_items = Item::find()->where('quantity >= 1 AND quantity <= 10')->all(); $empty_stock_items = Item::find()->where('quantity = 0')->all(); $logs = Log::find()->orderBy('created_at DESC')->limit(10)->all(); return $this->render('index', ['low_stock_items' => $low_stock_items, 'empty_stock_items' => $empty_stock_items, 'logs' => $logs]); }
/** * Run the database seeds. * * @return void */ public function run() { foreach (StoreInventories::where('fixed', 0)->get() as $inventory) { $inventory_items = ItemInventories::where('store_inventory_id', $inventory->id)->get(); foreach ($inventory_items as $item) { $t_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $item->other_barcode)->first(); if (empty($t_item)) { TempInventories::insert(array('id' => $item->id, 'store_inventory_id' => $item->store_inventory_id, 'division' => $item->division, 'category' => $item->category, 'category_long' => $item->category_long, 'sub_category' => $item->sub_category, 'brand' => $item->brand, 'sku_code' => $item->sku_code, 'other_barcode' => $item->other_barcode, 'description' => $item->description, 'description_long' => $item->description_long, 'lpbt' => $item->lpbt, 'conversion' => $item->conversion, 'ig' => $item->ig, 'fso_multiplier' => $item->fso_multiplier, 'sapc' => $item->sapc, 'whpc' => $item->whpc, 'whcs' => $item->whcs, 'so' => $item->so, 'fso' => $item->fso, 'fso_val' => $item->fso_val)); } } $inventory->fixed = 1; $inventory->update(); ItemInventories::where('store_inventory_id', $inventory->id)->delete(); $store = Store::where('storeid', $inventory->store_id)->first(); $skus = DB::table('store_items')->select('store_items.id', 'store_items.store_id', 'items.description', 'items.conversion', 'store_items.ig', 'store_items.fso_multiplier', 'items.lpbt', 'categories.category_long', 'sub_categories.sub_category', 'brands.brand', 'divisions.division', 'other_barcodes.other_barcode', 'items.sku_code')->join('stores', 'stores.id', '=', 'store_items.store_id')->join('items', 'items.id', '=', 'store_items.item_id')->join('other_barcodes', 'other_barcodes.item_id', '=', 'items.id')->join('categories', 'categories.id', '=', 'items.category_id')->join('sub_categories', 'sub_categories.id', '=', 'items.sub_category_id')->join('brands', 'brands.id', '=', 'items.brand_id')->join('divisions', 'divisions.id', '=', 'items.division_id')->whereRaw('other_barcodes.area_id = stores.area_id')->where('store_items.store_id', $store->id)->orderBy('items.id', 'asc')->get(); foreach ($skus as $sku) { $temp_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $sku->other_barcode)->first(); if (empty($temp_item)) { $item2 = Item::with('division')->with('category')->with('subcategory')->with('brand')->where('sku_code', $sku->sku_code)->first(); $fso = $sku->ig; if ($sku->fso_multiplier > $sku->ig) { $fso = $sku->fso_multiplier; } ItemInventories::insert(['store_inventory_id' => $inventory->id, 'division' => $item2->division->division, 'category' => $item2->category->category, 'category_long' => $item2->category->category_long, 'sub_category' => $item2->subcategory->sub_category, 'brand' => $item2->brand->brand, 'sku_code' => $item2->sku_code, 'other_barcode' => $sku->other_barcode, 'description' => $item2->description, 'description_long' => $item2->description_long, 'lpbt' => $item2->lpbt, 'conversion' => $sku->conversion, 'ig' => $sku->ig, 'fso_multiplier' => $sku->fso_multiplier, 'sapc' => 0, 'whpc' => 0, 'whcs' => 0, 'so' => $sku->ig, 'fso' => $fso, 'fso_val' => $item2->lpbt * $sku->ig]); } else { ItemInventories::insert(['store_inventory_id' => $temp_item->store_inventory_id, 'division' => $temp_item->division, 'category' => $temp_item->category, 'category_long' => $temp_item->category_long, 'sub_category' => $temp_item->sub_category, 'brand' => $temp_item->brand, 'sku_code' => $temp_item->sku_code, 'other_barcode' => $temp_item->other_barcode, 'description' => $temp_item->description, 'description_long' => $temp_item->description_long, 'lpbt' => $temp_item->lpbt, 'conversion' => $temp_item->conversion, 'ig' => $temp_item->ig, 'fso_multiplier' => $temp_item->fso_multiplier, 'sapc' => $temp_item->sapc, 'whpc' => $temp_item->whpc, 'whcs' => $temp_item->whcs, 'so' => $temp_item->so, 'fso' => $temp_item->fso, 'fso_val' => $temp_item->fso_val]); } } } }
public function items() { $fileName = "Items Mastefile.csv"; $writer = WriterFactory::create(Type::CSV); // for CSV files $writer->openToBrowser($fileName); // stream data directly to the browser $writer->addRow(array('Category Long Description', 'Category Short Description', 'SKU Code', 'Barcode', 'Item Short Description', 'Item Long Description', 'Conversion', 'Sub Category', 'Brand', 'Division', 'LPBT/Cond Value (PC)', 'Status')); $items = Item::select(\DB::raw('category_long, category, sku_code, barcode, description, description_long, conversion, sub_category, brand, division, lpbt, items.active'))->join('categories', 'categories.id', '=', 'items.category_id')->join('sub_categories', 'sub_categories.id', '=', 'items.sub_category_id')->join('brands', 'brands.id', '=', 'items.brand_id')->join('divisions', 'divisions.id', '=', 'items.division_id')->get(); $pluckdata = []; foreach ($items as $item) { $data[0] = $item->category_long; $data[1] = $item->category; $data[2] = $item->sku_code; $data[3] = $item->barcode; $data[4] = $item->description; $data[5] = $item->description_long; $data[6] = $item->conversion; $data[7] = $item->sub_category; $data[8] = $item->brand; $data[9] = $item->division; $data[10] = $item->lpbt; if ($item->active == '1') { $data[11] = 'Active'; } else { $data[11] = 'In-active'; } $pluckdata[] = $data; } $writer->addRows($pluckdata); // add multiple rows at a time $writer->close(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // $item = \App\Models\Item::find($id); $item->delete(); return redirect('toDo'); }
/** * Update the specified resource in storage. * * @param ProductRequest $request * @param int $id * @return \Illuminate\Http\Response */ public function update(ProductRequest $request, $id) { $input = $request->all(); $input['type'] = 'Product'; Item::find($id)->update($input); return redirect()->route('product.index')->withMessage('Product has been Updated')->withStatus('success'); }
public function show($id) { $invoice = Invoice::getInvoiceDetails($id); $items = Item::all(); // print_r($items); return view('invoice', ['invoice' => $invoice, 'id' => $id, 'items' => $items->getArray()]); }
/** * Lists all BillItem models. * @return mixed */ public function actionIndex() { if (isset($_POST['hasEditable']) && $_POST['hasEditable'] == 1) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if (isset($_POST['item'], $_POST['quantity_user'])) { if (!isset(Yii::$app->session['item'])) { Yii::$app->session['item'] = []; } $item = Yii::$app->session['item']; $item[$_POST['item']] = $_POST['quantity_user']; Yii::$app->session['item'] = $item; return ['output' => $_POST['quantity_user'], 'message' => '']; } else { return ['output' => '', 'message' => 'Validation error']; } } elseif (isset($_POST['iks'], $_POST['bks'], $_POST['assign_mode'])) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; //Create assignment if ($_POST['assign_mode'] == 1) { $items = Item::findAll($_POST['iks']); $bill = Bill::findOne($_POST['bks'][0]); $billItem = null; $transaction = Bill::getDb()->beginTransaction(); try { foreach ($items as $item) { $billItem = BillItem::find()->where(['item_id' => $item->id, 'bill_id' => $bill->id])->one(); if ($billItem == null) { $billItem = new BillItem(); $billItem->bill_id = $bill->id; $billItem->item_id = $item->id; } $itemSession = Yii::$app->session['item']; $oldQuantity = $billItem->quantity; $billItem->quantity = $itemSession[$item->id]; if ($oldQuantity > $billItem->quantity) { $item->quantity += $billItem->quantity; } elseif ($oldQuantity < $billItem->quantity) { $item->quantity -= $billItem->quantity; } $item->save(false); if (!$billItem->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($billItem->tableName())), 'msj' => print_r($billItem->getErrors(), true)]), 500); } } $transaction->commit(); Yii::$app->session['item'] = []; return ['error' => false, 'message' => Yii::t('app', 'Saved')]; } catch (\Exception $e) { $transaction->rollBack(); return ['error' => true, 'message' => print_r($e, true)]; } } } $searchModel = new BillSearch(); $dataProvider = $searchModel->searchWithItem(Yii::$app->request->queryParams); $itemSearchModel = new ItemSearch(); $itemDataProvider = $itemSearchModel->searchWithItem(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'itemSearchModel' => $itemSearchModel, 'itemDataProvider' => $itemDataProvider]); }
/** * 新商品 */ public function save() { $item = new Item(); $item->cat_id = Input::get('cat_id'); $item->name = Input::get('name'); $item->sku = Input::get('sku'); $item->price = Input::get('price'); $destinationPath = ""; $fileName = date(''); if (Request::hasFile('logo')) { $file = Request::file('logo'); Request::file('photo')->move($destinationPath, $fileName); } var_dump($file); exit; $item->save(); }
public function run() { $i = 0; do { Item::create(['name' => $i . '-item', 'completed' => false]); $i++; } while ($i <= 10); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $item = Item::whereId($id)->first(); if (empty($item)) { return $this->saveResponse(false); } return $this->saveResponse($item->delete()); }
/** * Handle the command. * * @param CreateItemCommand $command * @return boolean */ public function handle(CreateItemCommand $command) { $item = Item::create(['category_id' => $command->category_id, 'title' => $command->title, 'description' => $command->description, 'extra_description' => $command->extra_description, 'amount' => $command->amount, 'switch' => (int) $command->switch]); if (!empty($item)) { return $item; } return false; }
public function indexAction($test = null) { $items = Item::find(); // throw new ApiException('f**k!'); $this->setMessage(':D'); $this->setError('D:'); return $items; }
public function remove() { // Get task $listItem = $this->getTask(); // Remove task Item::find($listItem)->delete(); return redirect()->back(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $request = Topup::find($id); $items = Item::lists('name', 'id'); $item = $request->item_id; $testCategories = TestCategory::lists('name', 'id'); $testCategory = $request->test_category_id; return view('inventory.request.edit')->with('testCategories', $testCategories)->with('items', $items)->with('item', $item)->with('request', $request)->with('testCategory', $testCategory); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $this->validation_rules($request); $itemUpdate = $request->input(); $item = Item::find($id); $item->update($itemUpdate); Session::flash('flash_message', 'Data item layanan berhasil diupdate!'); return redirect('admin/item'); }
/** * Show the form for creating a new resource. * * @return Response */ public function create($id) { //Create stock // Get item $item = Item::find($id); // Get suppliers for select list $suppliers = Supplier::lists('name', 'id'); return View::make('inventory.stock.create')->with('item', $item)->with('suppliers', $suppliers); }
public function get_item_info(Request $request) { if ($request->ajax()) { $item_id = $request->input('item_id'); // $iteminfo = Item::find($item_id); $iteminfo = Item::get_measurement_unit($item_id); return response()->json($iteminfo); } }
/** * Count duplicate fields * If check is done while updating data then check except this id * * @param string $field_name * @param array $fields * @return int */ public function duplicateField($field_name, $fields) { $field_count = Item::where($field_name, $fields['name']); if (!empty($fields['item_id'])) { $field_count = $field_count->where('id', '!=', $fields['item_id']); } $field_count = $field_count->count(); return $field_count; }
public function delete(Request $request, $banqueId, $itemId) { // verify request inputs if (is_null($itemId)) { return response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST); } else { $item = Item::where('id_Item', '=', $itemId)->delete(); return is_null($item) ? response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST) : $item; } }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { parent::boot($router); Route::bind('items', function ($id) { return Item::forCurrentUser()->findOrFail($id); }); Route::bind('categories', function ($id) { return Category::forCurrentUser()->findOrFail($id); }); }
/** * Updates an existing Menu model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $dataProvider = new ActiveDataProvider(['query' => Item::find()->joinWith('menuItems')->where(['menu_id' => $model->menu_id]), 'pagination' => ['pageSize' => 10]]); $all_items = Item::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->menu_id]); } else { return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider, 'all_items' => $all_items]); } }
/** * @test * @return void */ public function it_can_delete_an_item() { DB::beginTransaction(); $this->logInUser(); $item = Item::first(); $response = $this->call('DELETE', '/api/items/' . $item->id); $this->assertEquals(204, $response->getStatusCode()); $response = $this->call('DELETE', '/api/item/' . $item->id); $this->assertEquals(404, $response->getStatusCode()); DB::rollBack(); }
public function add($itemId) { // Cart::add(455, 'Sample Item', 100.99, 2, array()); /* 取得商品信息 */ $item = Item::where('id', '=', $itemId)->first(); // var_dump($item);exit; /* 初始化要插入购物车的基本件数据 */ $parent = array('user_id' => Auth::id(), 'goods_id' => $itemId, 'sku' => $item['sku'], 'item_name' => addslashes($item['name']), 'price' => $item['price']); Cart::add($itemId, addslashes($item['name']), $item['price'], '1', array()); return redirect()->route('cart.index'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store() { //Check if exists $cost = Cost::exists($this->month, $this->year); if (!empty($cost)) { return $this->saveResponse(false); } $setting = Setting::first(); $spend = Item::total($this->month, $this->year); $cost = Bus::dispatch(new CreateCostCommand($setting->salary, $setting->save, $spend)); return $this->saveResponse($cost); }
/** * @test */ public function it_can_show_an_item() { $this->logInUser(); $item = Item::forCurrentUser()->first(); $response = $this->call('GET', '/api/items/' . $item->id); $content = json_decode($response->getContent(), true); // dd($content); $this->checkItemKeysExist($content); $this->checkItemKeysExist($content['children'][0]); $this->checkItemKeysExist($content['breadcrumb'][0]); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); }