public function StockCreationExample() { $metric = new Metric(); $metric->name = 'Unit'; $metric->symbol = 'U'; $metric->save(); //Now, create a category to store the inventory record under: $category = new Category(); $category->name = 'VoIP'; $category->save(); $item = new Inventory(); $item->metric_id = $metric->id; $item->category_id = $category->id; $item->name = 'SNOM Headset'; $item->description = 'Very nice for the ear'; $item->save(); $location = new Location(); $location->name = 'Snowball Small Stock Room'; $location->save(); $item->createStockOnLocation(2, $location); $item->createSku('PART1234'); dd($item->sku_code); //$res = Inventory::findBySku(Input::get('sku')); //$item = Inventory::find(1); //dd($item); $supplier = new Supplier(); //Mandatory fields $supplier->name = 'Miro Distribution'; //Optional fields $supplier->address = 'Montague Gardens'; $supplier->postal_code = '8000'; $supplier->zip_code = '12345'; $supplier->country = 'South Africa'; $supplier->region = 'Western Cape'; $supplier->city = 'Cape Town'; $supplier->contact_title = 'Sales Rep'; $supplier->contact_name = 'Mark Sparky'; $supplier->contact_phone = '555 555-5555'; $supplier->contact_fax = '555 555-5556'; $supplier->contact_email = '*****@*****.**'; $supplier->save(); $item = Inventory::find(1); //$supplier = Supplier::find(1); $item->addSupplier($supplier); }
public function testScopedInventories() { $metric = new Metric(); $metric->name = 'Test Metric'; $metric->symbol = 'Test Symbol'; $metric->save(); $productsCategory = Category::create(['name' => 'Products', 'belongs_to' => 'Products']); $miscCategory = Category::create(['name' => 'Misc', 'belongs_to' => 'Misc']); $noItemCategory = Category::create(['name' => 'No Items']); $productItem = Inventory::create(['name' => '', 'category_id' => $productsCategory->id, 'metric_id' => $metric->id]); $miscItem = Inventory::create(['name' => 'Item 1', 'category_id' => $miscCategory->id, 'metric_id' => $metric->id]); $miscItem2 = Inventory::create(['name' => 'Item 2', 'category_id' => $miscCategory->id, 'metric_id' => $metric->id]); $this->assertEquals(0, $noItemCategory->inventories()->count()); $this->assertEquals(1, $productsCategory->inventories()->count()); $this->assertEquals(2, $miscCategory->inventories()->count()); }
public function testGetTotalVariantStock() { $this->newCategory(); $this->newMetric(); $coke = Inventory::create(['name' => 'Coke', 'description' => 'Delicious Pop', 'metric_id' => 1, 'category_id' => 1]); $cherryCoke = $coke->createVariant('Cherry Coke'); $cherryCoke->makeVariantOf($coke); $vanillaCherryCoke = $cherryCoke->createVariant('Vanilla Cherry Coke'); $vanillaCherryCoke->makeVariantOf($cherryCoke); DB::shouldReceive('beginTransaction')->once()->andReturn(true); DB::shouldReceive('commit')->once()->andReturn(true); Event::shouldReceive('fire')->once()->andReturn(true); $location = $this->newLocation(); // Allow duplicate movements configuration option Config::shouldReceive('get')->twice()->andReturn(true); // Stock change reasons (one for create, one for put, for both items) Lang::shouldReceive('get')->times(4)->andReturn('Default Reason'); $cherryCoke->createStockOnLocation(20, $location); $vanillaCherryCoke->createStockOnLocation(20, $location); $this->assertEquals(40, $coke->getTotalVariantStock()); }
public function testInventoryDoesNotHaveCategory() { $this->newInventory(); $item = Inventory::find(1); $item->category_id = null; $item->save(); $this->assertFalse($item->hasCategory()); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $input = Input::all(); Inventory::find($id)->update($input); return Redirect::route('inventory.index')->with('message', 'Inventory item updated.'); }
public function testInventoryGetStockFromLocationInvalidLocation() { $this->newInventoryStock(); $item = Inventory::find(1); Lang::shouldReceive('get')->once(); try { $item->getStockFromLocation('testing'); $passes = false; } catch (\Exception $e) { $passes = true; } $this->assertTrue($passes); }