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;
     }
 }
 /** @depends testCreateFull */
 public function testCreateGuessMissingNoStock()
 {
     $item = new InventoryItem(null, $this->products[0]->id, null, 1, 2, 3, null, 5);
     $inv = new Inventory(stdtimefstr("2001-01-01 00:00:00"), $this->locations[0]->id);
     $inv->addItem($item);
     $srv = new InventoriesService();
     $id = $srv->create($inv);
     $this->assertNotEquals(false, $id, "Creation failed");
     $pdo = PDOBuilder::getPDO();
     $stmt = $pdo->prepare("SELECT * FROM STOCK_INVENTORYITEM");
     $this->assertNotEquals(false, $stmt->execute(), "Query failed");
     if ($row = $stmt->fetch()) {
         $this->assertEquals(0, $row["MISSINGQTY"]);
         $this->markTestIncomplete("Check unit value");
     } else {
         $this->assertTrue(false, "No inventory item found after creation");
     }
 }