/** @depends testConstruct */ public function testBuild() { $inv = Inventory::__build(1, 1000, 1); $this->assertEquals(1, $inv->id); $this->assertEquals(1000, $inv->date); $this->assertEquals(1, $inv->locationId); }
protected function proceed() { $srv = new InventoriesService(); switch ($this->action) { case 'save': $jsInv = json_decode($this->getParam("inventory")); $id = null; if (!property_exists($jsInv, 'id')) { $jsInv->id = null; } $inv = Inventory::__build($jsInv->id, $jsInv->date, $jsInv->locationId); foreach ($jsInv->items as $item) { if (!property_exists($item, 'missingQty')) { $item->missingQty = null; } if (!property_exists($item, 'unitValue')) { $item->unitValue = null; } if (!property_exists($item, "attrSetInstId")) { $item->attrSetInstId = null; } $item = new InventoryItem($inv->id, $item->productId, $item->attrSetInstId, $item->qty, $item->lostQty, $item->defectQty, $item->missingQty, $item->unitValue); $inv->addItem($item); } $inv->fillZero(); $id = $srv->create($inv); if ($id !== false) { $this->succeed($id); } else { $this->fail(APIError::$ERR_GENERIC); } break; } }
protected function build($dbInv, $pdo = null) { $db = DB::get(); $inv = Inventory::__build($dbInv['ID'], $db->readDate($dbInv['DATE']), $dbInv['LOCATION_ID'], $dbInv['PRODUCT_ID'], $dbInv['ATTRSETINST_ID'], $dbInv['QTY'], $dbInv['LOSTQTY'], $dbInv['DEFECTQTY'], $dbInv['MISSINGQTY'], $dbInv['UNITVALUE']); $stmt = $pdo->prepare("SELECT * FROM STOCK_INVENTORYCONTENT WHERE " . "INVENTORY_ID = :id"); $stmt->bindParam(":id", $dbInv['ID']); $stmt->execute(); while ($row = $stmt->fetch()) { $item = new InventoryItem($row['PRODUCT_ID'], $row['ATTRSETINST_ID'], $row['QTY'], $row['LOSTQTY'], $row['DEFECTQTY'], $row['MISSINGQTY'], $row['UNITVALUE']); $inv->addItem($item); } return $inv; }