Example #1
0
	/* Add existing datasheets */
	$datasheetQuery = "SELECT datasheeturl FROM datasheets WHERE part_id = ".$part["id"];
	$r3 = mysql_query($datasheetQuery);
	while ($res = mysql_fetch_assoc($r3)) {
			$attachment = new PartAttachment();
			$attachment->setPart($oPart);
			$attachment->replaceFromURL($res["datasheeturl"]);
			$attachment->setDescription(PartKeepr::i18n("Datasheet"));
			$oPart->getAttachments()->add($attachment);

		
	}
	
	PartKeepr::getEM()->persist($oPart);
	
	$oStock = new StockEntry($oPart, $part["instock"]);
	
	$priceQuery = "SELECT AVG(preis) AS preis FROM preise WHERE part_id = ".$part["id"];
	
	$r2 = mysql_query($priceQuery);
	$res = mysql_fetch_assoc($r2);
	
	if ($res) {
		if ($res["preis"] !== null) {
			$oStock->setPrice(floatval($res["preis"]));	
		}
	}
	
	PartKeepr::getEM()->persist($oStock);
	
	/* Add some random parameters */
Example #2
0
	public function addStock () {
		$part = PartManager::getInstance()->getPart($this->getParameter("part"));
		
		$user = SessionManager::getCurrentSession()->getUser();
		
		$stock = new StockEntry($part, intval($this->getParameter("stock")), $user);
		
		$price = floatval($this->getParameter("price"));
		
		if ($price != 0) {
			$stock->setPrice($price);
		}
		
		PartKeepr::getEM()->persist($stock);
		PartKeepr::getEM()->flush();
		
		$part->updateStockLevel();
		
		PartKeepr::getEM()->flush();
		
		return true;
	}