Пример #1
0
	public function get () {
		$qb = PartKeepr::getEM()->createQueryBuilder();
		
		$qb->select("se")->from("de\RaumZeitLabor\PartKeepr\Stock\StockEntry","se")
		->where("se.part = :part")
		->orderBy("se.dateTime", "DESC")
		->setParameter("part", $this->getParameter("item"));
		
		$results = $qb->getQuery()->getResult();
		
		$aData = array();
		
		foreach ($results as $result) {
			$aData[] = array(
				"username" => is_object($result->getUser()) ? $result->getUser()->getUsername() : PartKeepr::i18n("Unknown User"),
				"amount" => abs($result->getStockLevel()),
				"datetime" => $result->getDateTime()->format("Y-m-d H:i:s"),
				"id" => $result->getId(),
				"direction" => ($result->getStockLevel() < 0) ? "out" : "in",
				"price" => $result->getPrice()
			);	
		}
		

		return array("data" => $aData);
	}
Пример #2
0
	/**
	 * Sets the packaging unit for a specific distributor.
	 * 
	 * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the
	 * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below
	 * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack
	 * instead of 10.
	 *   
	 * @param int $packagingUnit The amount of items in one package
	 * @throws \de\RaumZeitLabor\PartKeepr\Part\OutOfRangeException When the packaging unit is less than 1
	 */
	public function setPackagingUnit ($packagingUnit) {
		$packagingUnit = intval($packagingUnit);
		
		if ($packagingUnit < 1) {
			$exception = new OutOfRangeException(PartKeepr::i18n("Packaging Unit is out of range"));
			$exception->setDetail(PartKeepr::i18n("The packaging unit must be 1 or higher"));
			throw $exception;
		}
		
		$this->packagingUnit = $packagingUnit;
	}
Пример #3
0
	public function __construct () {
		parent::__construct(PartKeepr::i18n("Username or Password wrong."));
	}
Пример #4
0
	public function __construct ($class, $id) {
		parent::__construct(
			sprintf(
				PartKeepr::i18n("The entity %s with the id %d could not be found"),
				$class,	$id));
	}
Пример #5
0
		$randomManufacturer = rand(0, count($aManufacturers)-1);
		$oPart->getManufacturers()->add(new PartManufacturer($oPart, $aManufacturers[$randomManufacturer]));
	}
	
	$oPart->getDistributors()->add(new PartDistributor($oPart, $aDistributors[$part["id_supplier"]]));
	
	//echo "Migrating part ".sprintf("%-40s", $part["name"])."\r";
	
	/* 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) {
Пример #6
0
	/**
	 * Deletes the footprint with the given id.
	 * 
	 * @param int $id The footprint id to delete
	 * @throws \de\RaumZeitLabor\PartKeepr\Util\SerializableException
	 */
	public function deleteFootprint ($id) {
		$footprint = Footprint::loadById($id);
		
		try {
			PartKeepr::getEM()->remove($footprint);
			PartKeepr::getEM()->flush();	
		} catch (\PDOException $e) {
			if ($e->getCode() == "23000") {
				$exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s is in use by some parts!"), $footprint->getName()));
				$exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getName()));
			
				throw $exception;
			}
		}
	}
	public function __construct ($username) {
		parent::__construct(
			sprintf(
				PartKeepr::i18n("User %s already exists."),
				$username));
	}
Пример #8
0
	/**
	 * (non-PHPdoc)
	 * @see de\RaumZeitLabor\PartKeepr\Util.Serializable::serialize()
	 */
	public function serialize () {
		$aManufacturers = array();
		
		foreach ($this->getManufacturers() as $manufacturer) {
			$aManufacturers[] = $manufacturer->serialize();
		}
		
		$aDistributors = array();
		
		foreach ($this->getDistributors() as $distributor) {
			$aDistributors[] = $distributor->serialize();
		}
		
		$aParameters = array();
		foreach ($this->getParameters() as $parameter) {
			$aParameters[] = $parameter->serialize();
		}
		
		$aImages = array();
		foreach ($this->getImages() as $image) {
			$aImages[] = $image->serialize();
		}
		
		$aAttachments = array();
		foreach ($this->getAttachments() as $attachment) {
			$aAttachments[] = $attachment->serialize();
		}
		
		return array(
					"id" => $this->getId(),
					"name" => $this->getName(),
					"comment" => $this->getComment(),
					"stockLevel" => $this->getStockLevel(),
					"footprint_id" => is_object($this->footprint) ? $this->footprint->getId() : null,
					"minStockLevel" => $this->minStockLevel,
					"storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null,
					"storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null,
					"category_id" => is_object($this->category) ?  $this->category->getId() : null,
					"partUnit_id" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null,
					"partUnit_name" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : PartKeepr::i18n("Pieces"),
					"partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "",
					"manufacturers" => $aManufacturers,
					"distributors" => $aDistributors,
					"images" => $aImages,
					"attachments" => $aAttachments,
					"parameters" => $aParameters
		
		);
	}
Пример #9
0
	/**
	 * Deletes the given category ID.
	 * @param $id int The category id to delete
	 * @throws CategoryNotFoundException If the category wasn't found
	 */
	public function deleteCategory ($id) {
		$category = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $id);
		
		
		if ($category) {
			try {
				$category = new NodeWrapper($category, $this->getNodeManager());
				
				if ($category->hasChildren()) {
					$exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName()));
					$exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName()));
				
					throw $exception;
				}
				$category->delete();	
			} catch (\PDOException $e) {
				if ($e->getCode() == "23000") {
					$exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName()));
					$exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName()));
				
					throw $exception;
				}
			}
			
		} else {
			throw new CategoryNotFoundException($id);
		}
	}
	public function __construct () {
		parent::__construct(PartKeepr::i18n("Storage Location not found."));
	}
Пример #11
0
	public function __construct ($id) {
		parent::__construct(sprintf(PartKeepr::i18n("Category %d not found."), $id));
	}
Пример #12
0
	public function __construct ($username) {
		parent::__construct(
			sprintf(
				PartKeepr::i18n("The user %s doesn't exist. Maybe the user was already deleted."),
				$username));
	}