public function getCurrentStats()
 {
     $aData = array();
     $aData["partCount"] = PartManager::getInstance()->getPartCount();
     $aData["categoryCount"] = PartCategoryManager::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" => PartUnit::loadById($row["puid"])->getName(), "stockLevel" => $row["stockLevel"]);
     }
     $aData["units"] = $aUnits;
     return $aData;
 }
 public function createSnapshot()
 {
     $snapshot = new StatisticSnapshot();
     $snapshot->setParts(PartManager::getInstance()->getPartCount());
     $snapshot->setCategories(PartCategoryManager::getInstance()->getCategoryCount());
     $result = PartUnitManager::getInstance()->getUnitCounts();
     foreach ($result as $row) {
         $snapshotUnit = new StatisticSnapshotUnit();
         $snapshotUnit->setPartUnit(PartUnit::loadById($row["puid"]));
         $snapshotUnit->setStatisticSnapshot($snapshot);
         if ($row["stockLevel"] !== null) {
             $snapshotUnit->setStockLevel($row["stockLevel"]);
         } else {
             $snapshotUnit->setStockLevel(0);
         }
         $snapshot->getUnits()->add($snapshotUnit);
     }
     PartKeepr::getEM()->persist($snapshot);
     PartKeepr::getEM()->flush();
 }
Example #3
0
 /**
  * Deserializes the part
  * @param array $parameters The array with the parameters to set
  */
 public function deserialize(array $parameters)
 {
     foreach ($parameters as $key => $value) {
         switch ($key) {
             case "name":
                 $this->setName($value);
                 break;
             case "description":
                 $this->setDescription($value);
                 break;
             case "comment":
                 $this->setComment($value);
                 break;
             case "internalPartNumber":
                 $this->setInternalPartNumber($value);
                 break;
             case "footprint":
                 if ($value === 0) {
                     $this->setFootprint(null);
                 } else {
                     try {
                         $footprint = Footprint::loadById($value);
                         $this->setFootprint($footprint);
                     } catch (\Exception $e) {
                         // No footprint was found. Ignore it.
                     }
                 }
                 break;
             case "minStockLevel":
                 $this->setMinStockLevel($value);
                 break;
             case "partUnit":
                 $partUnit = PartUnit::loadById($value);
                 $this->setPartUnit($partUnit);
                 break;
             case "category":
                 $category = PartCategory::loadById($value);
                 $this->setCategory($category);
                 break;
             case "status":
                 $this->setStatus($value);
                 break;
             case "storageLocation":
                 $storageLocation = StorageLocation::loadById($value);
                 $this->setStorageLocation($storageLocation);
                 break;
             case "manufacturers":
                 $this->deserializeChildren($value, $this->getManufacturers(), "PartKeepr\\Part\\PartManufacturer");
                 foreach ($this->getManufacturers() as $manufacturer) {
                     $manufacturer->setPart($this);
                 }
                 break;
             case "distributors":
                 $this->deserializeChildren($value, $this->getDistributors(), "PartKeepr\\Part\\PartDistributor");
                 foreach ($this->getDistributors() as $distributor) {
                     $distributor->setPart($this);
                 }
                 break;
             case "parameters":
                 $this->deserializeChildren($value, $this->getParameters(), "PartKeepr\\PartParameter\\PartParameter");
                 foreach ($this->getParameters() as $parameter) {
                     $parameter->setPart($this);
                 }
                 break;
             case "needsReview":
                 $this->setReviewFlag($value);
                 break;
             case "partCondition":
                 $this->setCondition($value);
                 break;
             case "attachments":
                 $this->deserializeChildren($value, $this->getAttachments(), "PartKeepr\\Part\\PartAttachment");
                 foreach ($this->getAttachments() as $attachment) {
                     $attachment->setPart($this);
                 }
                 break;
         }
     }
 }