Esempio n. 1
0
 public function create()
 {
     $this->requireParameter("name");
     $partUnit = new PartUnit();
     $partUnit->deserialize($this->getParameters());
     PartKeepr::getEM()->persist($partUnit);
     PartKeepr::getEM()->flush();
     return array("data" => $partUnit->serialize());
 }
Esempio n. 2
0
 /**
  * Sets up the default part unit if none exists
  */
 public function run()
 {
     $dql = "SELECT COUNT(p) FROM PartKeepr\\Part\\PartUnit p WHERE p.is_default = :default";
     $query = $this->entityManager->createQuery($dql);
     $query->setParameter("default", true);
     if ($query->getSingleScalarResult() == 0) {
         $partUnit = new PartUnit();
         $partUnit->setName(PartKeepr::i18n("Pieces"));
         $partUnit->setShortName(PartKeepr::i18n("pcs"));
         $partUnit->setDefault(true);
         $this->entityManager->persist($partUnit);
         $this->entityManager->flush();
         $this->logMessage("Added default part unit");
     } else {
         $this->logMessage("Skipped adding default part unit, because a default part unit already exists");
     }
 }
Esempio n. 3
0
 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();
 }
Esempio n. 5
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;
         }
     }
 }