예제 #1
0
	public function createSnapshot () {
		
		$snapshot = new StatisticSnapshot();
		$snapshot->setParts(PartManager::getInstance()->getPartCount());
		$snapshot->setCategories(CategoryManager::getInstance()->getCategoryCount());
		
		$result = PartUnitManager::getInstance()->getUnitCounts();
		
		foreach ($result as $row) {
			$snapshotUnit = new StatisticSnapshotUnit();
			$snapshotUnit->setPartUnit($row[0]);
			$snapshotUnit->setStatisticSnapshot($snapshot);
			$snapshotUnit->setStockLevel($row["stockLevel"]);
			$snapshot->getUnits()->add($snapshotUnit);
		}
		
		PartKeepr::getEM()->persist($snapshot);
		PartKeepr::getEM()->flush();
	}
예제 #2
0
		public function getCurrentStats () {

			$aData = array();
			$aData["partCount"] = PartManager::getInstance()->getPartCount();
			$aData["categoryCount"] = CategoryManager::getInstance()->getCategoryCount();
			$aData["totalPrice"] = PartManager::getInstance()->getTotalPrice();
			$aData["averagePrice"] = PartManager::getInstance()->getAveragePrice();
			$aData["partsWithPrice"] = PartManager::getInstance()->getPartCount(true);
			$aData["partsWithoutPrice"] = $aData["partCount"] - $aData["partsWithPrice"];
			
			$result = PartUnitManager::getInstance()->getUnitCounts();
	
			$aUnits = array();
			
			foreach ($result as $row) {
				$aUnits[] = array(
					"name" => $row[0]->getName(),
					"stockLevel" => $row["stockLevel"]);
			}
			
			$aData["units"] = $aUnits;
			
			return $aData;
		}
예제 #3
0
function addCategoryRecursive ($aCategories, $currentId, $parent) {
	global $newCategories;
	
	foreach ($aCategories as $aCategory) {
		if ($aCategory["parentnode"] == $currentId) {
			echo "Adding ".sprintf("%40s", $aCategory["name"])."\r";			
			$oCategory = new Category();
			$oCategory->setName(convertText($aCategory["name"]));
			$oCategory->setDescription("");
			$oCategory->setParent($parent->getId());
			$category = CategoryManager::getInstance()->addCategory($oCategory);
			
			addCategoryRecursive($aCategories, $aCategory["id"], $category);
			
			$newCategories[$aCategory["id"]] = $oCategory;
		}
	}
	
}
예제 #4
0
	public function addOrUpdatePart ($aParameters) {
		
		if (!array_key_exists("quantity", $aParameters)) {
			$aParameters["quantity"] = 0;
		}
		
		if ($aParameters["part"] !== null) {
			try {
				$part = $this->getPart($aParameters["part"]);
			} catch (\Exception $e) {
				$part = new Part();
				$user = SessionManager::getCurrentSession()->getUser();
		
				$stock = new StockEntry($part, $aParameters["quantity"], $user);
				PartKeepr::getEM()->persist($stock);
			}
		} else {
			$part = new Part();
			
			$user = SessionManager::getCurrentSession()->getUser();
		
			$stock = new StockEntry($part, $aParameters["quantity"], $user);
			PartKeepr::getEM()->persist($stock);
		}
		
		if (array_key_exists("name", $aParameters)) {
			$part->setName($aParameters["name"]);
		}
		
		if (array_key_exists("minstock", $aParameters)) {
			$part->setMinStockLevel($aParameters["minstock"]);
		}
		
		if (array_key_exists("comment", $aParameters)) {
			$part->setComment($aParameters["comment"]);
		}
		
		if (array_key_exists("footprint", $aParameters)) {
			
			if ($aParameters["footprint"] === null) {
				$part->setFootprint(null);	
			} else {
				$footprint = FootprintManager::getInstance()->getOrCreateFootprint($aParameters["footprint"]);
				$part->setFootprint($footprint);
			}
		}
		
		if (array_key_exists("storagelocation", $aParameters)) {
			$storageLocation = StorageLocationManager::getInstance()->getOrCreateStorageLocation($aParameters["storagelocation"]);
			$part->setStorageLocation($storageLocation);
		}
		
		if (array_key_exists("category", $aParameters)) {
			$category = CategoryManager::getInstance()->getCategory($aParameters["category"]);
			$part->setCategory($category->getNode());	
		}
		
		/* Process linked changes */
		if (array_key_exists("distributorChanges", $aParameters)) {
			if (is_array($aParameters["distributorChanges"])) {
				$this->processDistributorChanges($part, $aParameters["distributorChanges"]);
			}
		}
		
		if (array_key_exists("manufacturerChanges", $aParameters)) {
			if (is_array($aParameters["manufacturerChanges"])) {
				$this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]);
			}
		}
		
		if (array_key_exists("parameterChanges", $aParameters)) {
			if (is_array($aParameters["parameterChanges"])) {
				$this->processParameterChanges($part, $aParameters["parameterChanges"]);
			}
		}
		
		if (array_key_exists("attachmentChanges", $aParameters)) {
			if (is_array($aParameters["attachmentChanges"])) {
				$this->processAttachmentChanges($part, $aParameters["attachmentChanges"]);
			}
		}
		
		if (array_key_exists("partUnit", $aParameters)) {
			if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) {
				$part->setPartUnit(null);
			} else {
				$part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"]));
			}
		}
		
		
		PartKeepr::getEM()->persist($part);
		PartKeepr::getEM()->flush();
		
	}
예제 #5
0
	/**
	 * Returns all categories
	 */
	public function getAllCategories () {
		return $this->serializeTree(CategoryManager::getInstance()->getAllCategories());
	}