partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit ca96e1b58800c48642b95e0b4b6cf7cebd6cda62
parent ce614909b27bf25f40eb2d37c98520dff8588656
Author: Timo A. Hummel <timo@netraver.de>
Date:   Tue,  7 Jun 2011 15:23:59 +0200

Added initial statistics

Diffstat:
Mfrontend/index.html | 2++
Mfrontend/js/Components/MenuBar.js | 8++++++++
Afrontend/js/Components/Statistics/CurrentStatisticsDialog.js | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php | 10++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartManager.php | 10++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartUnit.php | 6++++++
Msrc/de/RaumZeitLabor/PartDB2/PartDB2.php | 4+++-
Msrc/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php | 8++++++++
Asrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php | 34++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php | 34++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 397 insertions(+), 1 deletion(-)

diff --git a/frontend/index.html b/frontend/index.html @@ -105,6 +105,8 @@ <script type="text/javascript" src="js/Components/PartUnit/PartUnitEditorComponent.js"></script> <script type="text/javascript" src="js/Components/PartUnit/PartUnitGrid.js"></script> + <script type="text/javascript" src="js/Components/Statistics/CurrentStatisticsDialog.js"></script> + <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> diff --git a/frontend/js/Components/MenuBar.js b/frontend/js/Components/MenuBar.js @@ -24,6 +24,10 @@ Ext.define('PartDB2.MenuBar', { text: i18n('Edit Part Units'), handler: this.editPartUnits, icon: "resources/silkicons/table.png" + },{ + text: i18n("Statistics"), + handler: this.showStatistics, + icon: 'resources/silkicons/chart_bar.png' }] }); @@ -36,6 +40,10 @@ Ext.define('PartDB2.MenuBar', { this.callParent(); }, + showStatistics: function () { + var j = Ext.create("PartDB2.CurrentStatisticsDialog"); + j.show(); + }, editStorageLocations: function () { var j = Ext.create("PartDB2.StorageLocationEditorComponent", { title: i18n("Storage Locations"), diff --git a/frontend/js/Components/Statistics/CurrentStatisticsDialog.js b/frontend/js/Components/Statistics/CurrentStatisticsDialog.js @@ -0,0 +1,70 @@ +Ext.define('PartDB2.CurrentStatisticsDialog', { + extend: 'Ext.window.Window', + width: 400, + height: 200, + title: i18n("Current Statistics"), + bodyStyle: { + padding: "5px" + }, + /** + * Initializes the component and adds a template + */ + initComponent: function () { + /** + * Create the template + */ + this.tpl = new Ext.XTemplate( + '<h1>'+i18n("Current Statistics")+'</h1>', + '<table>', + '<tr>', + '<td style="width: 100px;" class="o">'+i18n("Different Parts")+':</td>', + '<td style="width: 300px;" class="o">{partCount}</td>', + '</tr>', + '<tr>', + '<td class="e">'+i18n("Categories")+':</td>', + '<td class="e">{categoryCount}</td>', + '</tr>', + '</table>', + '<h1>'+i18n("Counts per Unit")+'</h1>', + '<table>', + '<tpl for="units">', + '<tr>', + '<td style="width: 100px;" class="{[xindex % 2 === 0 ? "e" : "o"]}">{name}</td>', + '<td style="width: 300px;" class="{[xindex % 2 === 0 ? "e" : "o"]}">{stockLevel}</td>', + '</tr>', + '</tpl>', + '</table>'); + + this.tbButtons = [{ + text: i18n("Refresh"), + handler: this.loadStats, + scope: this + },{ + text: i18n("Close"), + handler: this.close, + scope: this + }]; + + this.dockedItems = [{ + xtype: 'toolbar', + dock: 'bottom', + ui: 'footer', + items: this.tbButtons + }]; + + this.callParent(); + + this.loadStats(); + }, + loadStats: function () { + var call = new PartDB2.ServiceCall( + "Statistic", + "getCurrentStats"); + + call.setHandler(Ext.bind(this.onStatsLoaded, this)); + call.doCall(); + }, + onStatsLoaded: function (data) { + this.tpl.overwrite(this.getTargetEl(), data); + } +});+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php b/src/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php @@ -124,4 +124,14 @@ class CategoryManager extends Singleton { throw new CategoryNotFoundException; } } + + /** + * Returns the overall category count currently existing. + * @return int The amount of categories in the database + */ + public function getCategoryCount () { + $dql = "SELECT COUNT(c.id) FROM de\RaumZeitLabor\PartDB2\Category\Category c"; + + return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); + } } \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php @@ -271,4 +271,14 @@ class PartManager extends Singleton { return $part; } + + /** + * Returns the overall part count currently existing. + * @return int The amount of parts in the database + */ + public function getPartCount () { + $dql = "SELECT COUNT(p.id) FROM de\RaumZeitLabor\PartDB2\Part\Part p"; + + return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); + } } \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php b/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php @@ -38,6 +38,12 @@ class PartUnit { private $is_default; /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part",mappedBy="partUnit") + */ + private $parts; + + + /** * Creates a new part unit. * * Sets the default to false. diff --git a/src/de/RaumZeitLabor/PartDB2/PartDB2.php b/src/de/RaumZeitLabor/PartDB2/PartDB2.php @@ -181,7 +181,9 @@ class PartDB2 { 'de\RaumZeitLabor\PartDB2\Image\Image', 'de\RaumZeitLabor\PartDB2\Image\CachedImage', 'de\RaumZeitLabor\PartDB2\Image\TempImage', - 'de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo' + 'de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo', + 'de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot', + 'de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshotUnit' ); } diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php @@ -85,4 +85,12 @@ class PartUnitManager extends Singleton { PartDB2::getEM()->commit(); } + + public function getUnitCounts () { + $dql = 'SELECT SUM(p.stockLevel) AS stockLevel, pu FROM de\RaumZeitLabor\PartDB2\Part\PartUnit pu LEFT JOIN pu.parts p GROUP BY pu.id'; + + $result = PartDB2::getEM()->createQuery($dql)->getResult(); + + return $result; + } } \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php @@ -0,0 +1,33 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Service\Service; +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Part\PartManager, + de\RaumZeitLabor\PartDB2\Category\CategoryManager, + de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager; + +class StatisticService extends Service { + public function getCurrentStats () { + + $aData = array(); + $aData["partCount"] = PartManager::getInstance()->getPartCount(); + $aData["categoryCount"] = CategoryManager::getInstance()->getCategoryCount(); + + $result = PartUnitManager::getInstance()->getUnitCounts(); + + $aUnits = array(); + + foreach ($result as $row) { + $aUnits[] = array( + "name" => $row[0]->getName(), + "stockLevel" => $row["stockLevel"]); + } + + $aData["units"] = $aUnits; + + return $aData; + } + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php @@ -0,0 +1,111 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2; + + +/** @Entity **/ +class StatisticSnapshot { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * Defines the date when this snapshot has been taken + * @Column(type="datetime") + * @var DateTime + */ + private $dateTime; + + /** + * Defines the amount of different parts in the database + * @Column(type="integer") + * @var int + */ + private $parts; + + /** + * Defines the amount of categories + * @Column(type="integer") + * @var int + */ + private $categories; + + /** + * Holds all defined units in the database + * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshotUnit",mappedBy="statisticSnapshot",cascade={"persist", "remove"}) + */ + private $units; + + /** + * Creates a new statistic snapshot + */ + public function __construct () { + $this->units = new \Doctrine\Common\Collections\ArrayCollection(); + $this->setDateTime(new \DateTime()); + } + + /** + * Sets the date+time for the snapshot + * @param \DateTime $dateTime The date+time for the snapshot + */ + public function setDateTime (\DateTime $dateTime) { + $this->dateTime = $dateTime; + } + + /** + * Returns the date+time for the snapshot + * @return DateTime The date+time for the snapshot + */ + public function getDateTime () { + return $this->dateTime; + } + + /** + * Sets the amount of overall parts for the snapshot + * @param int $parts The amount of parts + */ + public function setParts ($parts) { + $this->parts = $parts; + } + + /** + * Returns the amount of overall parts for the snapshot + * @return int The amount of parts + */ + public function getParts () { + return $this->parts; + } + + /** + * Sets the amount of categories for the snapshot + * @param int $categories The amount of categories + */ + public function setCategories ($categories) { + $this->categories = $categories; + } + + /** + * Returns the amount of categories + * @return int The amount of categories + */ + public function getCategories () { + return $this->categories; + } + + /** + * Returns the ID of this snapshot + * @return int The ID of this snapshot + */ + public function getId () { + return $this->id; + } + + public function getUnits () { + return $this->units; + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php @@ -0,0 +1,33 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Util\Singleton, + de\RaumZeitLabor\PartDB2\Part\PartUnit, + de\RaumZeitLabor\PartDB2\Part\PartManager, + de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager, + de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Category\CategoryManager, + de\RaumZeitLabor\PartDB2\PartUnit\Exceptions\PartUnitNotFoundException; + +class StatisticSnapshotManager extends Singleton { + 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); + } + + PartDB2::getEM()->persist($snapshot); + PartDB2::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php @@ -0,0 +1,98 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Statistic; + +use de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot; +use de\RaumZeitLabor\PartDB2\Part\PartUnit; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2; + + +/** @Entity **/ +class StatisticSnapshotUnit { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot") + * The statistic snapshot this entity belongs to + * @var StatisticSnapshot + */ + private $statisticSnapshot; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartUnit") + * The statistic snapshot this entity belongs to + * @var StatisticSnapshot + */ + private $partUnit; + + /** + * The stockLevel for the unit + * @Column(type="integer") + * @var int + */ + private $stockLevel; + + /** + * Sets the statistic snapshot this entity belongs to + * @param StatisticSnapshot $snapshot The snapshot + */ + public function setStatisticSnapshot (StatisticSnapshot $snapshot) { + $this->statisticSnapshot = $snapshot; + } + + /** + * Returns the snapshot this entity belongs to + * @return StatisticSnapshot The snapshot + */ + public function getStatisticSnapshot () { + return $this->statisticSnapshot; + } + + /** + * + * Sets the part unit for this entity + * @param PartUnit $unit The part unit + */ + public function setPartUnit (PartUnit $unit) { + $this->partUnit = $unit; + } + + /** + * Returns the part unit for this entity + * @return PartUnit The part unit + */ + public function getPartUnit () { + return $this->partUnit; + } + + /** + * Returns the ID of this statistic snapshot unit + * @return int The ID + */ + public function getId () { + return $this->id; + } + + /** + * Sets the stock level for this unit snapshot + * @param int $stockLevel + */ + public function setStockLevel ($stockLevel) { + $this->stockLevel = $stockLevel; + } + + /** + * Returns the stock level for this unit snapshot + * @return int The stock level + */ + public function getStockLevel () { + return $this->stockLevel; + } +}+ \ No newline at end of file